I have a cloud formation script which I am using to create a Lambda and SNS Topic.
Here is the yml script for SNS Topic and Lambda creation,
SampleSNSTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: sampleTopic
TopicName: sampleTopic
SampleLambdaFunction:
Type: AWS::Lambda::Function
DependsOn: SampleSNSTopic
Properties:
Handler: index.handler
Description: Sample Lambda function
FunctionName: TestFunction
Role: !Ref SomeRole
Code:
ZipFile: !Sub |
var AWS = require("aws-sdk");
exports.handler = function(event, context) {
var eventText = JSON.stringify(event, null, 2);
var sns = new AWS.SNS();
var params = {
Message: eventText,
TopicArn: !Ref SampleSNSTopic
};
sns.publish(params, context.done);
};
Runtime: nodejs6.10
Timeout: 300
MemorySize: 512
Question: Using a !Ref on topic ARN fails,
TopicArn: !Ref SampleSNSTopic
Is this the right way to do it? Or is there some other way where I can use my SNS topic's ARN to create lambda in cloud formation?