You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Postman中提供SQSEvent对象测试SQS触发的Lambda函数

如何在Postman中为SQS触发的Lambda函数提供SQSEvent输入

要在Postman中测试SQS触发的Lambda函数,你需要构造符合AWS SQSEvent规范的JSON请求体,具体步骤如下:

  1. 构造SQSEvent格式的JSON
    SQSEvent的核心结构包含Records数组,每个元素代表一条SQS消息,示例如下:

    {
      "Records": [
        {
          "messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
          "receiptHandle": "test-receipt-handle",
          "body": "你的实际消息内容",
          "attributes": {
            "ApproximateReceiveCount": "1",
            "SentTimestamp": "1690000000000",
            "SenderId": "123456789012",
            "ApproximateFirstReceiveTimestamp": "1690000001000"
          },
          "messageAttributes": {},
          "md5OfBody": "7b270e59b47ff90a553787216d55d91d",
          "eventSource": "aws:sqs",
          "eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:YourQueueName",
          "awsRegion": "us-east-1"
        }
      ]
    }
    

    根据你的需求修改body、eventSourceARN、awsRegion等字段即可;如果需要测试多消息场景,在Records数组中添加更多消息对象。

  2. 配置Postman请求

    • 选择POST请求,目标URL为本地Lambda的调用端点(比如使用SAM本地时,地址通常是http://localhost:9000/2015-03-31/functions/your-function-name/invocations)
    • 切换到Body标签,选择raw格式,下拉菜单中选JSON
    • 将构造好的SQSEvent JSON粘贴到请求体中
    • 发送请求,Lambda即可识别并处理该SQSEvent输入

注意事项

  • 如果你的Lambda需要处理带属性的SQS消息,可在messageAttributes字段中添加符合规范的键值对,例如:
    "messageAttributes": {
      "AttributeName": {
        "stringValue": "AttributeValue",
        "dataType": "String"
      }
    }
    
  • 确保本地Lambda运行环境(如AWS SAM CLI、Lambda Runtime Emulator)已正确启动,能接收POST格式的调用请求

内容的提问来源于stack exchange,提问作者Jalaj Goyal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 12:33:17