我有以下设置:
API Gateway > Kinesis > Lambda
正在调用API网关,但进入Lambda函数的数据为空。
exports.handler = (event, context, callback) => {
event.Records.forEach((record) => {
console.log('record', record);
}
}
我得到了......
的输出{ kinesisSchemaVersion: '1.0',
partitionKey: 'some-partition-key',
sequenceNumber: '49572842939259722444903461552052718872116185957331369986',
data: 'e30=',
approximateArrivalTimestamp: 1494948079.296 },
eventSource: 'aws:kinesis',
eventVersion: '1.0',
eventID: 'shardId-000000000000:49572842939259722444903461552052718872116185957331369986',
eventName: 'aws:kinesis:record',
invokeIdentityArn: 'arn:aws:iam::************:role/service-role/basic-lambda-execute-role',
awsRegion: 'eu-west-1',
eventSourceARN: 'arn:aws:kinesis:eu-west-1:************:stream/sensor-readings' }
感兴趣点有data: 'e30='
如果我从APIG Method Test表单调用端点,结果是一样的。它显示了以下响应,对我来说看起来很好。
Execution log for request test-request
Wed May 17 08:36:45 UTC 2017 : Starting execution for request: test-invoke-request
Wed May 17 08:36:45 UTC 2017 : HTTP Method: POST, Resource Path: /reading
Wed May 17 08:36:45 UTC 2017 : Method request path: {}
Wed May 17 08:36:45 UTC 2017 : Method request query string: {}
Wed May 17 08:36:45 UTC 2017 : Method request headers: {}
Wed May 17 08:36:45 UTC 2017 : Method request body before transformations: {
"version" : "0.01",
"concentrator": {
"id": "con123",
"rssi": -87,
"snr": 10.1,
"gwid": "Gateway1"
},
"client": {
"name": "LukesTestDB",
"site": "TheSite"
},
"data": [
{
"timestamp": "1486124533248000000",
"ch0": "10",
"ch1": "34",
"ch2": "56",
"ch3": "78"
}
],
"device": {
"id": "DEV_789",
"rssi": "100",
"chx": "ch0",
"asset": "MyAsset",
"bType": "MyBType",
"feed": "MyFeed",
"location": "MyLocation",
"other": "MyOther",
"timestamp": "1486124533248000000"
}
}
Wed May 17 08:36:45 UTC 2017 : Endpoint request URI: https://kinesis.eu-west-1.amazonaws.com/?Action=PutRecord
Wed May 17 08:36:45 UTC 2017 : Endpoint request headers: {Authorization=*******************************************************************************************************************************************************************************************************************************************************************************************************0c8175, X-Amz-Date=20170517T083645Z, x-amzn-apigateway-api-id=aawfu1iss2, Accept=application/json, User-Agent=AmazonAPIGateway_aawfu1iss2, X-Amz-Security-Token=AgoGb3JpZ2luEAQaCWV1LXdlc3QtMSKAAk80yYO4cLZv4RB1ThK+Fc4ZShZ33tUtXfk19XEBCknow94tmnaaTKXDhqd9TM/Fn6yGJC/vHQG3OEV9eWUVtGvx6GYAv98p0NV98jNxIniIncsQP6xcOL+Q4mN1MT7/pXd5WrjCPJntNJ5KKblfmuTlZXYZvp0f7hWK6+wOs2vD0BT3WJh2hMPxfuokfXO4M2rnHhPEcav6MLzxZtA8fnW+6uQoESGS1MnD9Vxua3JEeM7OwK0nWv2118RvIQIgKha+42Y9b3V6VnN6JqXkAOQDBI72YB5PcPXcJYUh1vNOUpGcUwGs/XDoqdHPcQM/yEHM3k7RxRSyug9a93vAhgUqgAIIKhAAGgw0MTk3NjIxMjExMTIiDDH8iXCSo6iQU7aIUCrdAZ1oQ7U6KYLyUONxLMg/YBv0ijO0rLlU4dzAXD5HsjtjKiyfc676EIsqMbP7WqLxdP1lHscMmZE4cnIcGxm94mwFypWyrTYW3ZAhWnuM [TRUNCATED]
Wed May 17 08:36:45 UTC 2017 : Endpoint request body after transformations: {
"Data": "eyJ2ZXJzaW9uIjoiMC4wMSIsImNvbmNlbnRyYXRvciI6eyJpZCI6ImNvbjEyMyIsInJzc2kiOi04Nywic25yIjoxMC4xLCJnd2lkIjoiR2F0ZXdheTEifSwiY2xpZW50Ijp7Im5hbWUiOiJMdWtlc1Rlc3REQiIsInNpdGUiOiJUaGVTaXRlIn0sImRhdGEiOlt7InRpbWVzdGFtcCI6IjE0ODYxMjQ1MzMyNDgwMDAwMDAiLCJjaDAiOiIxMCIsImNoMSI6IjM0IiwiY2gyIjoiNTYiLCJjaDMiOiI3OCJ9XSwiZGV2aWNlIjp7ImlkIjoiREVWXzc4OSIsInJzc2kiOiIxMDAiLCJjaHgiOiJjaDAiLCJhc3NldCI6Ik15QXNzZXQiLCJiVHlwZSI6Ik15QlR5cGUiLCJmZWVkIjoiTXlGZWVkIiwibG9jYXRpb24iOiJNeUxvY2F0aW9uIiwib3RoZXIiOiJNeU90aGVyIiwidGltZXN0YW1wIjoiMTQ4NjEyNDUzMzI0ODAwMDAwMCJ9fQ==",
"StreamName": "sensor-readings",
"PartitionKey": "some-partition-key"
}
Wed May 17 08:36:45 UTC 2017 : Endpoint response body before transformations: {"SequenceNumber":"49572842939259722444903521585275507706013464929106919426","ShardId":"shardId-000000000000"}
Wed May 17 08:36:45 UTC 2017 : Endpoint response headers: {Server=Apache-Coyote/1.1, x-amzn-RequestId=c6c9329d-b519-d631-975f-3f401e1e34d2, x-amz-id-2=l5W9SQ3x4cnc3vF/oKlWoHK8qFsfRzZTK9byAK/Rpo477Of3JSlLPMorjH4/KV0s2BRKQtsVwbvYahkKKqfHtQZ5uHK6dKBs, Content-Length=110, Date=Wed, 17 May 2017 08:36:45 GMT, Content-Type=application/x-amz-json-1.1}
Wed May 17 08:36:45 UTC 2017 : Method response body after transformations: {"SequenceNumber":"49572842939259722444903521585275507706013464929106919426","ShardId":"shardId-000000000000"}
Wed May 17 08:36:45 UTC 2017 : Method response headers: {X-Amzn-Trace-Id=Root=1-591c0b9d-cf38868aada300b710e2ab3d, Content-Type=application/json}
Wed May 17 08:36:45 UTC 2017 : Successfully completed execution
Wed May 17 08:36:45 UTC 2017 : Method completed with status: 200
在那里我们有......
"Data": "eyJ2ZXJzaW9uIjoiMC4wMSIsImNvbmNlbnRyYXRvciI6eyJpZCI6ImNvbjEyMyIsInJzc2kiOi04Nywic25yIjoxMC4xLCJnd2lkIjoiR2F0ZXdheTEifSwiY2xpZW50Ijp7Im5hbWUiOiJMdWtlc1Rlc3REQiIsInNpdGUiOiJUaGVTaXRlIn0sImRhdGEiOlt7InRpbWVzdGFtcCI6IjE0ODYxMjQ1MzMyNDgwMDAwMDAiLCJjaDAiOiIxMCIsImNoMSI6IjM0IiwiY2gyIjoiNTYiLCJjaDMiOiI3OCJ9XSwiZGV2aWNlIjp7ImlkIjoiREVWXzc4OSIsInJzc2kiOiIxMDAiLCJjaHgiOiJjaDAiLCJhc3NldCI6Ik15QXNzZXQiLCJiVHlwZSI6Ik15QlR5cGUiLCJmZWVkIjoiTXlGZWVkIiwibG9jYXRpb24iOiJNeUxvY2F0aW9uIiwib3RoZXIiOiJNeU90aGVyIiwidGltZXN0YW1wIjoiMTQ4NjEyNDUzMzI0ODAwMDAwMCJ9fQ=="
....这是发送给Kinesis的有效载荷的base64编码版本。
有谁能告诉我为什么我会在Lambda中获得data: 'e30='
或者我应该在哪里开始寻找?
非常感谢,
路。
答案 0 :(得分:0)
记住新手 - 先进先出(先入先出)
第一个确实是空的有效载荷,直到lambda能够处理,后续数据才会被处理。
我不断在流上推送新数据,希望能立即处理。
我无法看到树林里的树林!
我希望这可以帮助其他新手,或者让别人大笑:)
谢谢@driedel - 当我重新阅读你的评论时,它完全有道理。