使用Lambda将数据添加到Kinesis Firehose流中时出现ResourceNotFoundException

时间:2019-03-07 10:03:39

标签: aws-lambda python-3.6 boto3 amazon-kinesis-firehose

我正在尝试使用putrecord在AWS Lambda上使用python3.6将数据添加到Kinesis Firehose传递流中。在流上调用放置记录时,出现以下异常。

  

调用PutRecord操作时发生错误(ResourceNotFoundException):找不到帐户123456下的流MyStream。

我正在执行以下python代码以将数据添加到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 and other sources

1 个答案:

答案 0 :(得分:0)

如果确定流名称正确,则可以使用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

希望这会有所帮助!