(aws-events): Allow EventBridge Rule to Target Lambda by Alias or Version
See original GitHub issueWhen creating an EventBridge Rule with CDK, I want to target a lambda function Alias or Version. Targeting an alias or version is allowed in the AWS Console UI, but I cannot find this option through the CDK, the resulting targets the base lambda ARN, effectively pointing to $LATEST.
Use Case
We continuously deploy of our Lambdas through a CICD pipeline, but we manually “release” by pointing the Alias to a specific version. All our services reference our lambdas by alias/version (apigateway, sqs, sns, …)
Proposed Solution
Add an option for Alias or Version when creating an EventTarget
const awsEvents = require("@aws-cdk/aws-events");
const awsEventsTargets = require("@aws-cdk/aws-events-targets");
//my function
const lambdaFunction = new lambda.Function(this, generateConstructName("lambda"), {
runtime: lambda.Runtime.NODEJS_12_X,
code: lambda.Code.fromAsset(`../${FUNCTION_NAME}.zip`),
handler: "src/index.handler",
...
}
//event bridge
const myEventPayload = {...};
const eventTarget = new awsEventsTargets.LambdaFunction(lambdaFunction, {
event: awsEvents.RuleTargetInput.fromObject(myEventPayload),
version: <---- allow this ------
alias: <----or this ----------
});
const eventRule = new awsEvents.Rule(this, generateConstructName("event-rule"), {
enabled: true,
description: `event to invoke ${FUNCTION_NAME}`,
ruleName: "cdk-test-rule",
targets : [
eventTarget
],
schedule: awsEvents.Schedule.rate(EVENT_MEETING_SYNC_RATE)
});
Other
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How to use AWS CDK to set EventBridge Rule Target for ...
I found it: the event rule takes type IFunction , and since IAlias and IVersion both extend IFunction , so we can take...
Read more >Tutorial: Schedule AWS Lambda functions using EventBridge
To use the AWS CLI, you first grant the rule permission to invoke your Lambda function. Then you can create the rule and...
Read more >Troubleshooting Amazon EventBridge - 亚马逊云科技
The EventBridge console then sets the correct permissions on the target. If you're using a specific Lambda alias or version, add the --qualifier...
Read more >Why wasn't my Lambda function triggered by my EventBridge ...
Why wasn't my Lambda function triggered by my EventBridge rule ? ... More AWS events videos - http://bit.ly/316g9t4 ABOUT AWS Amazon Web ...
Read more >aws_cloudwatch_event_target | Resources | hashicorp/aws
Provides an EventBridge Target resource. ... target_id = "StopInstance" arn = "arn:aws:events:eu-west-1:1234567890:event-bus/My-Event-Bus" rule ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try
Alias.fromAliasAttributes()
orVersion.fromVersionArn/fromVersionAttributes()
This issue is not resolved. I have attempted the following:
const eventTarget = new awsEventsTargets.LambdaFunction(lambdaAlias, { event: awsEvents.RuleTargetInput.fromObject(meetingSyncEvent) });
This still targets the lambda and not the alias.
I have also attempting trying to set an “alias” Property of the EventRule using the methodology suggested above:
lambda_event_rule = _events.Rule( self, id=args["rule_name"], event_bus=_events.EventBus.from_event_bus_name(scope=self, id=args["event_bus_id"], event_bus_name=args["event_bus_name"]), rule_name=args["rule_name"], event_pattern=args["event_rule_patterns"][0], targets= [_targets.LambdaFunction(self.function, max_event_age=Duration.hours(2), retry_attempts=2 )], alias=self.alias.fromAliasAttributes() )
The rule gets created but never sets the "configure version/alias Option of the Rule, it still is generated as “Default” option.The event rule will trigger, but the lambda is never invoked. If I manually change the alias rule option to the name of the alias in the UI, the rule will then invoke the lambda.
The request is is to please enable the “version” and/or “alias” options above as requested and please provide a working code sample.