【问题标题】:ResourceNotFoundException while adding data to Kinesis Firehose stream using Lambda使用 Lambda 将数据添加到 Kinesis Firehose 流时出现 ResourceNotFoundException
【发布时间】:2019-07-29 04:10:21
【问题描述】:

我正在尝试在 aws lambda 上使用带有 python3.6 的 putrecord 将数据添加到 Kinesis Firehose 传输流。在流上调用 put record 时,出现以下异常。

调用PutRecord操作时发生错误(ResourceNotFoundException):找不到帐户123456下的Stream 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

【问题讨论】:

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


    【解决方案1】:

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

    希望对你有帮助!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-13
      • 2016-01-17
      • 2019-09-06
      • 2020-02-08
      • 2016-08-20
      • 2021-09-14
      • 2017-07-20
      相关资源
      最近更新 更多