仅当通过AWS CLI调用Lambda时,目标才有效 [英] Destination only works when Lambda is invoked through AWS CLI

查看:120
本文介绍了仅当通过AWS CLI调用Lambda时,目标才有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有配置为:hello-world的测试Lambda:

I have a hello-world test Lambda configured with:

  • 触发:API网关
  • 目的地:Amazon SQS.一个排队成功,另一个排队失败.
import json

def lambda_handler(event, context):
    print("Received event: " + json.dumps(event))

    return {
        "statusCode": 200,
        "body": 'success'
    }

当我通过CLI调用Lambda时,消息将按预期排队到成功队列中:

When I invoke the Lambda via the CLI, the message gets enqueued to the success queue as expected:

aws lambda invoke --function-name event-destinations --invocation-type Event --payload '{}' response.json

但是,当我通过API网关调用Lambda时,没有消息排队到任一目标队列中.我启用了Lambda代理集成. Cloudwatch指标确认调用成功(调用计数增加,错误计数不成功).以下代码从我的Lambda代码返回了200和预期的响应正文:

However, when I invoke the Lambda via the API Gateway, no messages are enqueued to either destination queue. I have Lambda Proxy Integration enabled. Cloudwatch metrics confirm that the invocation is successful (Invocations count goes up, Errors count does not). The following returns a 200 and and the expected response body from my Lambda code:

curl 'https://REDACTED.execute-api.us-east-1.amazonaws.com/api_trigger' \
--header 'Content-Type: application/json' \
--data-raw '{}'

类似地,当我使用Lambda控制台中的测试"按钮时,没有消息排队到任一目标队列中. edit:这是预期的行为

Similarly, no messages are enqueued to either destination queue when I use the Test button in the Lambda console. edit: this is expected behavior per https://www.trek10.com/blog/lambda-destinations-what-we-learned-the-hard-way

这3个调用之间的目的地行为为什么会有所不同?我已为此测试将重试次数设置为0.

Why would the destination behavior differ between these 3 invocations? I have set retry attempts to 0 for this test.

推荐答案

似乎有一组有效的{trigger,destination}对,而{API Gateway,SQS}不是其中之一.能够从给定的触发器调用lambda不足以使事件传递到目的地. AWS控制台不强制执行这些配对或发出警告.

It seems there is a set of valid {trigger, destination} pairs, and {API Gateway, SQS} is not one of them. Being able to invoke the lambda from a given trigger is not sufficient to get the event passed along to the destination. AWS console doesn't enforce these pairing or raise warnings.

我引用了以下图表: https://www.trek10.com/blog/lambda-destinations-what-we-learned-the-hard-way/

我在lambda中添加了一个S3触发器,并且S3事件没有问题地发布到了目标SQS队列中.

I added an S3 trigger to my lambda, and the S3 events are published to the destination SQS queues without issue.

这篇关于仅当通过AWS CLI调用Lambda时,目标才有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆