Helo, I am trying to add a trigger to a lambda function as follows. But it is throwing error as follows
undefined method `match' for {"Ref"=>"EventRuleName"}
I have already defined a lambda and event rule prior to the creating the permissions stack . But while running the permission stack it errored out
cloudformation
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: ""
Parameters:
LambdaFunctionName:
Type: String
Default: lambda-function1
EventBridgeRuleRoleName:
Type: String
Default: EventBridgeRuleRole1
EventRuleName:
Type: String
Default: EventBridgeRule1
Env:
Type: String
AWSTenant:
Type: String
TeamTag:
Type: String
Default: team1
Resources:
PermissionForEvent0ToInvokeLambda:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref LambdaFunctionName
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn:
Fn::GetAtt:
- !Ref EventRuleName
- "Arn"
You can't fetch the Arn from the EventRuleName
because that is a string parameter.
It would work if the EventRule is deployed in the same stack. Then you can use !Ref
and fetch the Arn of the EventRule.
If you need to separate the stacks, I would
PermissionForEvent0ToInvokeLambda:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref LambdaFunctionName
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn:
Fn::Sub:
- arn:aws:events:${AWS::Region}:${AWS::AccountId}:rule/${EventRuleName}