简体   繁体   中英

AWS SQS Send From Lambda should I use "Add Destination"?

I have a Lambda which is triggered by a message arriving on a SQS queue. I want to do some processing in the Lambda then forward a message to another SQS queue for further processing by another Lambda. It appears I can do this in two different ways:

  1. In the AWS Console Lambda Designer, user the "Add Destination" feature define a SQS queue as a destination
  2. Write node.js code to send a message to SQS from within my Lambda

What is the preferred/correct/recommended way to do it? What are the advantages and disadvantages of each?

The Destination function is rather new.

One benefit is has is that the Destination action is triggered by the AWS Lambda service, rather than the function itself. This can be quite useful in situations where the Lambda function does not have access to the Destination.

For example, imagine a VPC that does not have access to the Internet. An AWS Lambda function configured to use that VPC would not be able to call the Amazon SQS API since it resides on the Internet. However, using a Destination of Amazon SQS will work because the AWS Lambda service will send the message and this will be done outside of the VPC. (You could alternatively use a VPC Endpoint for SQS, but this is just an example.)

Also, please note that Destinations only work for Lambda functions that are invoked asynchronously .

If your flow includes so many small tasks, each task requires different type of payload, you may consider to write a small code to call each of them. As your final response, we may consider to return all results based on all small tasks so you can monitor the whole processes and log them into CloudWatch Logs.

If your flow relies on the final response, for each execution status code, for example:

  • {Status: OnSuccess} : triggers SNS topic
  • {Status: OnFailure} : sends to SQS queue

This feature helps you to reduce your code and make your Lambda more clean and clear.

It's better to write code to send your message. As AWS already offers send message functions you just need to pass the parameters.

It also recommended by AWS to delete the message programmatically.

SQS send message

SQS Delete message

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM