Key错误:AWS Lambda中的“记录”

时间:2019-07-29 11:32:00

标签: aws-lambda

我正在尝试创建Lambda,以将传入的XML消息从kinesis流转换为JSON并存储在S3中。

我创建了一个lambda包,并将其作为Lambda创建的一部分导入。在创建Lambda之后,当我从Lambda控制台进行测试时,出现错误:

Id

找到以下代码段:

[ERROR] KeyError: 'records'
Traceback (most recent call last):
  File "/var/task/kinesis_streaming_s3_v5.py", line 19, in lambda_handler
    for record in event ['records']:

谢谢。

1 个答案:

答案 0 :(得分:0)

Kinesis Data Stream使诸如以下的事件

{
  "Records": [
    {
      "kinesis": {
        "partitionKey": "partitionKey-03",
        "kinesisSchemaVersion": "1.0",
        "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IDEyMy4=",
        "sequenceNumber": "49545115243490985018280067714973144582180062593244200961",
        "approximateArrivalTimestamp": 1428537600
      },
      "eventSource": "aws:kinesis",
      "eventID": "shardId-000000000000:49545115243490985018280067714973144582180062593244200961",
      "invokeIdentityArn": "arn:aws:iam::EXAMPLE",
      "eventVersion": "1.0",
      "eventName": "aws:kinesis:record",
      "eventSourceARN": "arn:aws:kinesis:EXAMPLE",
      "awsRegion": "ap-northeast-2"
    }
  ]
}

records实际上是Records的地方。