如何指定从 SQS 到 AWS Lambda 的输入?
How to specify Input to AWS Lambda from SQS?
我创建了一个 lambda 函数,我想从 Amazon SQS 触发它。对于处理程序 (Event,Context) 中的事件值,我想从这个 SQS 中指定一个值。我想指定一个大JSON。我怎样才能做到这一点?
从 Sample Events Published by Event Sources - AWS Lambda,Amazon SQS 将此事件信息发送到 AWS Lambda 函数:
{
"Records": [
{
"messageId": "c80e8021-a70a-42c7-a470-796e1186f753",
"receiptHandle": "...",
"body": "{\"foo\":\"bar\"}",
"attributes": {
"ApproximateReceiveCount": "3",
"SentTimestamp": "1529104986221",
"SenderId": "594035263019",
"ApproximateFirstReceiveTimestamp": "1529104986230"
},
"messageAttributes": {},
"md5OfBody": "9bb58f26192e4ba00f01e2e7b136bbd8",
"eventSource": "aws:sqs",
"eventSourceARN": "arn:aws:sqs:us-west-2:594035263019:NOTFIFOQUEUE",
"awsRegion": "us-west-2"
}
]
SQS 消息的正文在 body
参数中提供。
maximum size of an SQS message 是 256 KB,但我不确定您能否将这么大的东西传递给 Lambda。我建议你试试看!
最坏的情况,将内容存储在 Amazon S3 中并在消息中传递对 S3 对象的引用。
创建 SQS 队列。此 SQS 队列应将 s3 存储桶名称作为输入。也许它也应该采用 s3 存储桶的区域?可能想让它带一个 JSON 对象:
{"bucketname": "this_is_my_bucket", "region": "us-west-2"}
我创建了一个 lambda 函数,我想从 Amazon SQS 触发它。对于处理程序 (Event,Context) 中的事件值,我想从这个 SQS 中指定一个值。我想指定一个大JSON。我怎样才能做到这一点?
从 Sample Events Published by Event Sources - AWS Lambda,Amazon SQS 将此事件信息发送到 AWS Lambda 函数:
{
"Records": [
{
"messageId": "c80e8021-a70a-42c7-a470-796e1186f753",
"receiptHandle": "...",
"body": "{\"foo\":\"bar\"}",
"attributes": {
"ApproximateReceiveCount": "3",
"SentTimestamp": "1529104986221",
"SenderId": "594035263019",
"ApproximateFirstReceiveTimestamp": "1529104986230"
},
"messageAttributes": {},
"md5OfBody": "9bb58f26192e4ba00f01e2e7b136bbd8",
"eventSource": "aws:sqs",
"eventSourceARN": "arn:aws:sqs:us-west-2:594035263019:NOTFIFOQUEUE",
"awsRegion": "us-west-2"
}
]
SQS 消息的正文在 body
参数中提供。
maximum size of an SQS message 是 256 KB,但我不确定您能否将这么大的东西传递给 Lambda。我建议你试试看!
最坏的情况,将内容存储在 Amazon S3 中并在消息中传递对 S3 对象的引用。
创建 SQS 队列。此 SQS 队列应将 s3 存储桶名称作为输入。也许它也应该采用 s3 存储桶的区域?可能想让它带一个 JSON 对象:
{"bucketname": "this_is_my_bucket", "region": "us-west-2"}