I am trying to a cloudformation template that deploys lambda function and an event rule that invokes the function every 10 minutes.
I am following the below articles for the template creation.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html
With the template i have created, the stack is getting created and the lambda functions are successfully deployed but when i include the event rule in the template, i am getting below error.
An error occurred (ValidationError) when calling the CreateChangeSet operation: Template error: instance of Fn::GetAtt references undefined resource autodeployment5
Below is the template i am using
{
"AWSTemplateFormatVersion":"2010-09-09",
"Description":"A template is for creating lambda from s3 buckets",
"Resources":{
"IamRoleLambdaExecution":{
"Type":"AWS::IAM::Role",
"Properties":{
"AssumeRolePolicyDocument":{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Principal":{
"Service":[
"lambda.amazonaws.com"
]
},
"Action":[
"sts:AssumeRole"
]
}
]
},
"Path":"/",
"RoleName":{
"Fn::Join":[
"-",
[
"CF-deployment-20-36-48",
"dev",
{
"Ref":"AWS::Region"
},
"lambdaRole"
]
]
}
}
},
"autodeployment5":{
"Type":"AWS::Lambda::Function",
"Properties":{
"FunctionName":"autodeployment5",
"Code":{
"S3Bucket":"sayway-etl",
"S3Key":"handler.zip"
},
"Description":"Used to run job",
"Handler":"handler.run_query",
"Runtime":"python3.9",
"MemorySize":10240,
"Timeout":900,
"EphemeralStorage":{
"Size":10240
},
"Role":{
"Fn::GetAtt":[
"IamRoleLambdaExecution",
"Arn"
]
},
"Layers":[
"arn:aws:lambda:eu-central-1:567567013174:layer:duckdb_U18:1",
"arn:aws:lambda:eu-central-1:567567013174:layer:libs_x86_64_linux:2",
"arn:aws:lambda:eu-central-1:336392948345:layer:AWSDataWrangler-Python39:7",
"arn:aws:lambda:eu-central-1:567567013174:layer:cachetools:1"
]
}
},
"ScheaduleRule":{
"Type":"AWS::Events::Rule",
"Properties":{
"Description":"LamdaScheaduleRule",
"ScheduleExpression":"rate(10 minutes)",
"State":"ENABLED",
"Targets":[
{
"Arn":{
"Fn::GetAtt":[
"autodeployment5",
"Arn"
]
},
"Id":"run_query"
}
]
}
},
"PermissionForEventsToInvokeLambda":{
"Type":"AWS::Lambda::Permission",
"Properties":{
"FunctionName": { "Ref": "autodeployment5" },
"Action":"lambda:InvokeFunction",
"Principal":"events.amazonaws.com",
"SourceArn":{
"Fn::GetAtt":[
"ScheaduleRule",
"Arn"
]
}
}
}
}
}