Movatterモバイル変換


[0]ホーム

URL:


Invoking a Lambda function asynchronously - AWS Lambda
DocumentationAWS LambdaDeveloper Guide

Invoking a Lambda function asynchronously

Several AWS services, such as Amazon Simple Storage Service (Amazon S3) and Amazon Simple Notification Service (Amazon SNS), invoke functions asynchronously to process events. You can also invoke a Lambda function asynchronously using the AWS Command Line Interface (AWS CLI) or one of the AWS SDKs. When you invoke a function asynchronously, you don't wait for a response from the function code. You hand off the event to Lambda and Lambda handles the rest. You can configure how Lambda handles errors, and can send invocation records to a downstream resource such as Amazon Simple Queue Service (Amazon SQS) or Amazon EventBridge (EventBridge) to chain together components of your application.

The following diagram shows clients invoking a Lambda function asynchronously. Lambda queues the events before sending them to the function.

Clients invoke a function asynchronously. Lambda queues events before sending them to the function

For asynchronous invocation, Lambda places the event in a queue and returns a success response without additional information. A separate process reads events from the queue and sends them to your function.

To invoke a Lambda function asynchronously using the AWS Command Line Interface (AWS CLI) or one of the AWS SDKs, set theInvocationType parameter toEvent. The following example shows an AWS CLI command to invoke a function.

aws lambda invoke \ --function-name my-function \--invocation-typeEvent \ --cli-binary-format raw-in-base64-out \ --payload '{ "key": "value" }' response.json

You should see the following output:

{    "StatusCode": 202}

Thecli-binary-format option is required if you're using AWS CLI version 2. To make this the default setting, runaws configure set cli-binary-format raw-in-base64-out. For more information, seeAWS CLI supported global command line options in theAWS Command Line Interface User Guide for Version 2.

The output file (response.json) doesn't contain any information, but is still created when you run this command. If Lambda isn't able to add the event to the queue, the error message appears in the command output.

Invoke a function synchronously
Error handling

[8]
ページ先頭

©2009-2025 Movatter.jp