Lambda asynchronous call

When you call a function asynchronously, Lambda send events to the queue. A separate process reads the events from the queue and run your function. After you add an event to the queue, Lambda will return a success response, rather than return to other information. Asynchronously call the function, please call type parameter set  Event.

Output file ( response.json) does not contain any information, but will still create this file when you run this command. If Lambda unable to add the event to the queue, an error message will be displayed in the command output.

Lambda asynchronous call queue management functions, and attempt to automatically retry failed events. If the function returns an error, Lambda will try to run again twice, wait a minute between the previous two attempts, wait two minutes between the second and third times. Error functions including error codes returned by the function, and returns the error function is running, such as timeouts. If all three attempts fail, Lambda event will be sent to the dead-letter queue (if configured).


      Lambda will be recorded in the sub-segments each attempt.

If it does not have enough available for concurrent handling of all events, the other requests will be limited. For the limit errors (429) and system errors (500 series), Lambda event will return to the queue and try to run again the function up to 6 hours. Retry interval increases exponentially from 1 second after the first attempt up to 5 minutes, but if the queue is backed up, it may be longer. Lambda also reduces the read events from the queue rate, and the event queue further return may not be read. Events can be located in the longest queue is four days.


      The request limit is shown as pending in the AWS X-Ray.

Even if your function does not return an error, it is also possible to receive several times the same event from Lambda, because the queue itself has a final consistency. If the function can not keep up with the incoming events, it is also possible to remove the event from the queue without sending it to the function. Make sure that your code works correctly handle repeating events function, and you have enough concurrent processing can be used for all calls.

AWS Lambda dead letter queue function

When all three attempts handle asynchronous call fails, Lambda can send events to the Amazon SQS queue or Amazon SNS topic. Use your dead letter queue configuration function to save these events for further processing.

If you do not queue or topic, please create a queue or topic. Select the target type for your use case matches.

To add an event sent to the queue or topic, your function requires additional permissions. Add function has to perform the role of policies required permissions.

After creating goals and performing the role update function will be added to the dead letter queue function. You can configure multiple functions to send events to the same destination.

Configuring Dead Letter Queue

  1. Open Lambda console  function page .

  2. Select the function.

  3. In  Debugging and error handling (debugging and error handling)  under the  DLQ resources to  Amazon SQS  or  Amazon the SNS .

  4. Select the destination queue or topic.

  5. Select  the Save .

To configure dead letter queue by AWS CLI, use the  update-function-configuration command.

 
$ aws lambda update-function-configuration --function-name my-function \ --dead-letter-config TargetArn=arn:aws:sns:us-east-2:123456789012:my-topic

Lambda AS sends an event to the dead letter queue, and other information contained in the attribute. You can use this information to identify the function returns an error, or the event log or AWS X-Ray tracing is associated.

DLQ message properties

  • The RequestID (String) - ID invocation request. Request ID is displayed in the log function. You can also use the X-Ray Development Kit on the track record in the property request ID, and then you can press the search request ID in X-Ray console. For an example, see the error handler example .

  • The ErrorCode (Digital) - HTTP status code.

  • The ErrorMessage (string) - the first 1 KB block of text of the error message.


      Dead Letter Queue event attribute Amazon SQS console.

If Lambda can not be sent to the dead-letter message queue, the event is removed and sent  DeadLetterErrors  indicators. The reason why this occurs, it may be due to lack of authority, or total message size exceeds the limit target queue or topic. For example, if the body close to 256 KB Amazon SNS notification trigger that caused the error function, the Amazon SNS add additional event data is combined with the Lambda added property may result DLQ message exceeds the maximum size allowed.

If you use Amazon SQS as an event source, on the Amazon SQS queue DLQ itself and not on the configuration function Lambda.

Guess you like

Origin www.cnblogs.com/cloudrivers/p/11619292.html