interface LambdaFunctionProps
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.Events.Targets.LambdaFunctionProps |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awseventstargets#LambdaFunctionProps |
Java | software.amazon.awscdk.services.events.targets.LambdaFunctionProps |
Python | aws_cdk.aws_events_targets.LambdaFunctionProps |
TypeScript (source) | aws-cdk-lib » aws_events_targets » LambdaFunctionProps |
Customize the Lambda Event Target.
Example
import * as lambda from 'aws-cdk-lib/aws-lambda';
const fn = new lambda.Function(this, 'MyFunc', {
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
code: lambda.Code.fromInline(`exports.handler = handler.toString()`),
});
const rule = new events.Rule(this, 'rule', {
eventPattern: {
source: ["aws.ec2"],
},
});
const queue = new sqs.Queue(this, 'Queue');
rule.addTarget(new targets.LambdaFunction(fn, {
deadLetterQueue: queue, // Optional: add a dead letter queue
maxEventAge: Duration.hours(2), // Optional: set the maxEventAge retry policy
retryAttempts: 2, // Optional: set the max number of retry attempts
}));
Properties
Name | Type | Description |
---|---|---|
dead | IQueue | The SQS queue to be used as deadLetterQueue. Check out the considerations for using a dead-letter queue. |
event? | Rule | The event to send to the Lambda. |
max | Duration | The maximum age of a request that Lambda sends to a function for processing. |
retry | number | The maximum number of times to retry when the function returns an error. |
deadLetterQueue?
Type:
IQueue
(optional, default: no dead-letter queue)
The SQS queue to be used as deadLetterQueue. Check out the considerations for using a dead-letter queue.
The events not successfully delivered are automatically retried for a specified period of time, depending on the retry policy of the target. If an event is not delivered before all retry attempts are exhausted, it will be sent to the dead letter queue.
event?
Type:
Rule
(optional, default: the entire EventBridge event)
The event to send to the Lambda.
This will be the payload sent to the Lambda Function.
maxEventAge?
Type:
Duration
(optional, default: Duration.hours(24))
The maximum age of a request that Lambda sends to a function for processing.
Minimum value of 60. Maximum value of 86400.
retryAttempts?
Type:
number
(optional, default: 185)
The maximum number of times to retry when the function returns an error.
Minimum value of 0. Maximum value of 185.