sam local generate-event sqs – 我想从SQS生成一个虚拟请求以发送给Lambda。

huangapple go评论76阅读模式
英文:

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"
    }
  ]
}

要了解其他服务的类似情况,请按照以下步骤进行:

  1. sam local generate-event --help - 这将列出可以生成事件的可能服务集。

  2. sam local generate-event sqs --help - 这将列出服务下可能的命令集(这里我选择了sqs)。

  3. 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:

  1. sam local generate-event --help - This will list the possible set of services for which event can be generated.

  2. sam local generate-event sqs --help - This will list the possible set of commands under the service (here I have selected sqs)

  3. sam local generate-event sqs receive-message --help - This will list the possible set of options under that command(only receive-message command is available under sqs service)

huangapple
  • 本文由 发表于 2023年1月6日 12:05:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75026835.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定