title: AWS CloudFormation for Lambda and SNS Topic
body: <p>I have a cloud formation script which I am using to create a Lambda and SNS Topic. </p>
  
  <p>Here is the yml script for SNS Topic and Lambda creation, </p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>Question:</strong> Using a !Ref on topic ARN fails,</p>
  
  <pre><code>TopicArn: !Ref SampleSNSTopic
  </code></pre>
  
  <p>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?</p>