5
votes

I have a hello-world test Lambda configured with:

  • trigger: API Gateway
  • destination: Amazon SQS. one queue for success, and another for failure.
import json

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

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

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

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 '{}'

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

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

1
You need to add some logs to your Lambda function to see what is happening.Mark B
Seems like the inputs are the same and the Lambda's not failing so it's going to be difficult to debug this without code.jarmod
@MarkB added the lambda code.user3281392

1 Answers

6
votes

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.

I referenced the chart from: https://www.trek10.com/blog/lambda-destinations-what-we-learned-the-hard-way/

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