I have a Lambda and an CloudWatch Rule that triggers the lambda. When I set these via the web console, I can see in the Lambda console that it's trigger is indeed the CloudWatch rule.
Now I want to set it from the AWS SAM YAML template, and the trigger is indeed being created as expected, but in the lambda web console it does not show the CloudWatch rule as a trigger.
Also, I need to set the lambda's VPC in the YAML, but there is no effect on the lambda.
I would appriciate if someone can have a look at the YAML and point me to the right directions:
Resources:
checkNoSessionLambda:
Type: AWS::Serverless::Function
Properties:
Description: 'checkNoSessionLambda at every 1 minute'
Handler: checkNoSessionLambda.handler
Runtime: nodejs8.10
Timeout: 60
CodeUri: ./src
Role: ***
VpcConfig:
SecurityGroupIds:
- "***"
SubnetIds:
- "***"
- "***"
Events:
CheckNoSessionClouadwatchRule:
Properties:
EventPattern:
source:
- "aws.events"
Type: AWS::Events::Rule
CheckNoSessionClouadwatchRule:
Type: AWS::Events::Rule
Properties:
Description: "Invoke checkNoSession lambda every 1 minute"
ScheduleExpression: "rate(1 minute)"
State: "ENABLED"
Targets:
-
Arn: "***"
Id: "checkNoSessionLambdaTargetId"
EDIT:
The Lambad is in a stack, so using simply the GetAtt isn't helping
Events
section on the function. All you need are 3 resources:AWS::Serverless::Function
,AWS::Events::Rule
as you've done (use!GetAtt
as per the answer below), and anAWS::Lambda::Permission
to grant the rule access to invoke your function. – 404