使用 Lambda 向 Kinesis Firehose 流添加数据时出现 ResourceNotFoundException [英] ResourceNotFoundException while adding data to Kinesis Firehose stream using Lambda
问题描述
我正在尝试使用 putrecord 在 aws lambda 上使用 python3.6.在流上调用 put record 时,出现以下异常.
I am trying to add data to Kinesis Firehose delivery stream using putrecord with python3.6 on aws lambda. When calling put record on the stream I get following exception.
调用 PutRecord 操作时发生错误(ResourceNotFoundException):未找到帐户 123456 下的 Stream MyStream.
An error occurred (ResourceNotFoundException) when calling the PutRecord operation: Stream MyStream under account 123456 not found.
我正在执行以下 python 代码以将数据添加到 Stream.
I am executing following python code to add data to Stream.
import boto3
import json
def lambda_handler(event, context):
session = boto3.Session(aws_access_key_id=key_id, aws_secret_access_key=access_key)
kinesis_client = session.client('kinesis', region_name='ap-south-1')
records = event['Records']
write_records = list()
count = 0
for record in records:
count += 1
if str(record['eventName']).lower() == 'insert':
rec = record['dynamodb']['Keys']
rec.update(record['dynamodb']['NewImage'])
new_record = dict()
new_record['Data'] = json.dumps(rec).encode()
new_record['PartitionKey'] = 'PartitionKey'+str(count)
# Following Line throws Exception
kinesis_client.put_record(StreamName="MyStream", Data=new_record['Data'], PartitionKey='PartitionKey'+str(count))
elif str(record['eventName']).lower() == 'modify':
pass
write_records = json.dumps(write_records)
print(stream_data)
MyStream 状态为活动状态,流数据的来源设置为 Direct PUT 和其他来源
MyStream status is active and source for the stream data is set to Direct PUT and other sources
推荐答案
如果确定流名称正确,则可以使用 Kinesis 的区域端点创建客户端
If you are sure that the stream name is correct, you can create client with regional endpoint of Kinesis
kinesis_client = session.client('kinesis', region_name='ap-south-1', endpoint_url='https://kinesis.ap-south-1.amazonaws.com/')
AWS 服务端点列表https://docs.aws.amazon.com/general/latest/gr/rande.html
希望这有帮助!!!
这篇关于使用 Lambda 向 Kinesis Firehose 流添加数据时出现 ResourceNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!