Amazon Lambda Destinations Library
This library provides constructs for adding destinations to a Lambda function.
Destinations can be added by specifying the
onSuccess props when creating a function or alias.
The following destinations are supported
- Lambda function
- SQS queue
- SNS topic
- EventBridge event bus
Example with a SNS topic for sucessful invocations:
When a lambda function is configured with a destination, an invocation record is created by the Lambda service when the lambda function completes. The invocation record contains the details of the function, its context, and the request and response payloads.
The following example shows the format of the invocation record for a successful invocation:
In case of failure, the record contains the reason and error object:
Destination-specific JSON format
- For SNS/SQS (
SqsDestination), the invocation record JSON is passed as the
Messageto the destination.
- For Lambda (
LambdaDestination), the invocation record JSON is passed as the payload to the function.
- For EventBridge (
EventBridgeDestination), the invocation record JSON is passed as the
detailin the PutEvents call. The value for the event field
lambda, and the value for the event field
detail-typeis either 'Lambda Function Invocation Result - Success' or 'Lambda Function Invocation Result – Failure', depending on whether the lambda function invocation succeeded or failed. The event field
resourcecontains the function and destination ARNs. See AWS Events for the different event fields.
Auto-extract response payload with lambda destination
responseOnly option of
LambdaDestination allows to auto-extract the response payload from the
In the above example,
destinationFn will be invoked with the payload returned by
responsePayload in the invocation record, not the full record).
When used with
onFailure, the destination function is invoked with the error object returned
by the source function.
responseOnly option allows to easily chain asynchronous Lambda functions without
having to deal with data extraction in the runtime code.