Can I use !Ref to reference an SNS topic defined in the same template? The following pseudo-code is basically what I'm trying to achieve. The function and topic gets created but the function does not have a trigger for the SNS topic automatically created.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs4.3
Timeout: 10
Events:
MyTopic:
Type: SNS
Properties:
Topic: !Ref ExampleTopic
ExampleTopic:
Type: "AWS::SNS::Topic"
Properties:
DisplayName: example
Your config has a bug. The Events section should be a key of the Properties dictionary like this for it to work:
Properties:
Handler: index.handler
Runtime: nodejs4.3
Timeout: 10
Events:
MyTopic:
Type: SNS
Properties:
Topic: !Ref ExampleTopic
Hi, I have exatly the same issue. SNS trigger is not getting created when i deploy my template.
There seems to be an issue with "AutoPublishAlias: test".
If i remove the alias, it works just fine.
AWSTemplateFormatVersion:` '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification template describing your function.
Resources:
SSM:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'SSM'
AutoPublishAlias: test
Handler: index.handler
Runtime: python3.6
CodeUri: .
Description: ''
MemorySize: 128
Timeout: 3
Role: 'arn:aws:iam::712115679703:role/Lambda-ssm-ec2'
DeploymentPreference:
Type: AllAtOnce
Events:
MyTopic:
Type: SNS
Properties:
Topic: !Ref SNSTopic
SNSTopic:
Type: 'AWS::SNS::Topic'
Properties:
DisplayName: SNSTopic
It would be nice if sam validate would complain about it. I've just spent a few hours just to find out the indentation was wrong :)
Most helpful comment
It would be nice if
sam validatewould complain about it. I've just spent a few hours just to find out the indentation was wrong :)