class LambdaFunction
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.Events.Targets.LambdaFunction |
Java | software.amazon.awscdk.services.events.targets.LambdaFunction |
Python | aws_cdk.aws_events_targets.LambdaFunction |
TypeScript (source) | @aws-cdk/aws-events-targets » LambdaFunction |
Implements
IRule
Use an AWS Lambda function as an event rule target.
Example
import * as lambda from '@aws-cdk/aws-lambda';
const fn = new lambda.Function(this, 'MyFunc', {
runtime: lambda.Runtime.NODEJS_14_X,
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: cdk.Duration.hours(2), // Optional: set the maxEventAge retry policy
retryAttempts: 2, // Optional: set the max number of retry attempts
}));
Initializer
new LambdaFunction(handler: IFunction, props?: LambdaFunctionProps)
Parameters
- handler
IFunction
- props
Lambda
Function Props
Methods
Name | Description |
---|---|
bind(rule, _id?) | Returns a RuleTarget that can be used to trigger this Lambda as a result from an EventBridge event. |
bind(rule, _id?)
public bind(rule: IRule, _id?: string): RuleTargetConfig
Parameters
- rule
IRule
- _id
string
Returns
Returns a RuleTarget that can be used to trigger this Lambda as a result from an EventBridge event.