I have created a Lambda function using the CDK.
In my Java application, I am programmatically creating a CloudWatch Event Rule with a target pointing to the function via its ARN.
The CloudWatch rule gets triggered but it fails to invoke the Lambda. When I manually add the CloudWatch rule as a trigger for the Lambda from AWS Console, the function does get invoked.
CDK code
private createPregameEventsLambda(props: InfraStackProps) {
const lambdaEnvVars = {
'Domain': props.stage,
'Region': props.region,
'ResourceNamePrefix': props.resourceNamePrefix
};
const pregameEventsLambda = new Lambda(this, "PregameEvents-Lambda", {
...props,
name: LambdaConfig.PREGAME_EVENTS_LAMBDA.name,
handler: LambdaConfig.PREGAME_EVENTS_LAMBDA.handler,
environment: {
variables: lambdaEnvVars
},
role: this.lambdaExecutionRole
}).getFunction()
}
Java application:
public void createCloudWatchRule(final LiveEventIdRelationInfo info) {
final String smpId = info.getSmpId();
final Date date = new Date(startTime);
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.setTimeZone(TimeZone.getTimeZone("GMT+0"));
final String cronExpression = getCronExpression(calendar);
final PutRuleRequest putRuleRequest = new PutRuleRequest()
.withScheduleExpression(cronExpression)
.withName(ruleName);
cloudWatchEventClient.putRule(putRuleRequest);
final Target target = new Target()
.withId(LAMBDA_TARGET_ID)
.withArn(functionArn)
.withInput(jsonString);
final PutTargetsRequest putTargetsRequest = new PutTargetsRequest()
.withRule(ruleName)
.withTargets(target);
cloudWatchEventClient.putTargets(putTargetsRequest);
}
Console shows that the Rule created has the correct Lambda ARN but it still does not get invoked.
Is there an InvokeFunction permission I need to add to the CDK code?
Am I missing permissions?