Reputation: 51
I'm using the AWS CDK to create a Event Bridge stack. In summary the idea is, the CDK project will be resposible to create the Event Bus, the rules and the targets.
In my scenario the targets are Lambda Functions that already exist.
I'm following this doc:
https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html#properties
I believe that the issue with the code below is that I'm not pointing to a bucket where the lambda exists but I can't point since I would like to point directly to the lambda function that is deployed.
Is it possible to accomplish it with the CDK?
const cdk = require('@aws-cdk/core');
const busCdk = require('@aws-cdk/aws-events')
const ruleCdk = require('@aws-cdk/aws-events')
const targets = require('@aws-cdk/aws-events-targets')
const functionCdk = require('@aws-cdk/aws-lambda')
class PocCdkStack extends cdk.Stack {
/**
*
* @param {cdk.Construct} scope
* @param {string} id
* @param {cdk.StackProps=} props
*/
constructor(scope, id, props) {
super(scope, id, props);
const bus = new busCdk.EventBus(this,'ProfileEventBus',{
eventBusName: "PocProfileBus"
})
const rule = new ruleCdk.Rule(this, "newRule", {
description: "description",
eventPattern: {
source: ["order_service"]
},
eventBus: bus
});
const func = new functionCdk.Function(this, 'testLambda', {
functionArn: 'arn:aws:lambda:us-east-1:111111111111:function:ccna-poc-eventbus-project-test-triggerByEventBusTwo'
});
rule.addTarget(new targets.LambdaFunction(func));
}
}
module.exports = { PocCdkStack }
Thank you all,
Upvotes: 2
Views: 6088
Reputation: 51
I believe that I have found the solution.
const func = functionCdk.Function.fromFunctionArn(this, 'testLambda', 'arn:aws:lambda:us-east-1:11111:function:ccna-poc-eventbus-project-test-triggerByEventBusTwo')
There is a static method that does the job.
Upvotes: 2