英文:
sam local generate-event sqs - I want to generate a dummy request to lambda from SQS
问题
我正在遵循官方文档,但它没有提供有关需要传递给特定事件源的参数的信息。在我的情况下是SQS。
我尝试运行
sam local generate-event sqs
在CLI中。但这会导致错误的语法情况。
我如何在本地使用SAM项目从SQS中测试Lambda?
我看到一些关于apigateway的示例代码,但不知道他们如何获得这些属性以在CLI中使用,
任何参考文档或代码示例都会有所帮助。
英文:
I was following the official documentation but it gives no information on the parameters that need to be passed for specific event sources. SQS in my case.
I tried running
sam local generate-event sqs
in the CLI. But that fails with the wrong syntax scenario.
How can I test lambda from an SQS in my local using SAM project?
I saw some sample code for apigateway, but no idea how they got those properties to be used in the CLI,
Any reference to documentation or code samples would be helpful.
答案1
得分: 1
在运行以下命令时:
sam local generate-event sqs receive-message --body '{"hello": "world"}'
,
您将收到以下形式的响应:
{
"Records": [
{
"messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
"receiptHandle": "MessageReceiptHandle",
"body": "{\"hello\": \"world\"}",
"attributes": {
"ApproximateReceiveCount": "1",
"SentTimestamp": "1523232000000",
"SenderId": "123456789012",
"ApproximateFirstReceiveTimestamp": "1523232000001"
},
"messageAttributes": {},
"md5OfBody": "49dfdd54b01cbcd2d2ab5e9e5ee6b9b9",
"eventSource": "aws:sqs",
"eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:MyQueue",
"awsRegion": "us-east-1"
}
]
}
要了解其他服务的类似情况,请按照以下步骤进行:
-
sam local generate-event --help
- 这将列出可以生成事件的可能服务集。 -
sam local generate-event sqs --help
- 这将列出服务下可能的命令集(这里我选择了sqs
)。 -
sam local generate-event sqs receive-message --help
- 这将列出该命令下可能的选项(仅在sqs
服务下可用receive-message
命令)。
英文:
On running the command:
sam local generate-event sqs receive-message --body '{"hello": "world"}'
, you will receive a response of the form:
{
"Records": [
{
"messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
"receiptHandle": "MessageReceiptHandle",
"body": "{"hello": "world"}",
"attributes": {
"ApproximateReceiveCount": "1",
"SentTimestamp": "1523232000000",
"SenderId": "123456789012",
"ApproximateFirstReceiveTimestamp": "1523232000001"
},
"messageAttributes": {},
"md5OfBody": "49dfdd54b01cbcd2d2ab5e9e5ee6b9b9",
"eventSource": "aws:sqs",
"eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:MyQueue",
"awsRegion": "us-east-1"
}
]
}
For figuring out the same for other services, follow the below steps:
-
sam local generate-event --help
- This will list the possible set of services for which event can be generated. -
sam local generate-event sqs --help
- This will list the possible set of commands under the service (here I have selectedsqs
) -
sam local generate-event sqs receive-message --help
- This will list the possible set of options under that command(onlyreceive-message
command is available undersqs
service)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论