# How to pass create SNS topic ARN to Lambda function

**URL:** <https://forum.serverless.com/t/how-to-pass-create-sns-topic-arn-to-lambda-function/3202>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [November 27, 2017, 7:05pm UTC](https://forum.serverless.com/t/how-to-pass-create-sns-topic-arn-to-lambda-function/3202 "2017-11-27T19:05:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![akaNightmare](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/akanightmare/32/1338_2.png) [@akaNightmare](https://forum.serverless.com/u/akaNightmare)\
**Post date:** [November 27, 2017, 7:05pm UTC](https://forum.serverless.com/t/how-to-pass-create-sns-topic-arn-to-lambda-function/3202/1 "2017-11-27T19:05:39Z")

</div>

Hi,  
I have serverless.yml configuration and in this file I trying to create some SNS Topic with some name. In Lambda function I want to use created SNS topic ARN for `sns.publish()`, but I don’t know how to pass created ARN to Lambda function. Thanks.  
Bellow you can find some serverless.yml

```
custom:
  webpackIncludeModules: true
  region: ${opt:region, "us-east-1"}
  stage: ${opt:stage, "prod"}
  snsTopicName: some-sns-topic-${self:custom.stage}
  snsTopicArn:
    Fn::Join:
      - ':'
      - - arn
        - aws
        - sns
        - Ref: AWS::Region
        - Ref: AWS::AccountId
        - ${self:custom.snsTopicName}
provider:
  name: aws
  runtime: nodejs6.10
  stage: ${self:custom.stage}
  region: ${self:custom.region}
  cfLogs: true
  iamRoleStatements:
- Effect: Allow
  Action:
    - s3:GetObject
    - s3:ListBucket
  Resource:
    - arn:aws:s3:::${self:custom.bucket}
    - arn:aws:s3:::${self:custom.bucket}/*
- Effect: Allow
  Action:
    - sns:Publish
  Resource:
    - ${self:custom.snsTopicArn}
functions:
  process:
    handler:handler.process
    timeout: 300
    memorySize: 128
    events:
      - s3:
          bucket: ${self:custom.bucket}
          event: s3:ObjectCreated:*
          rules:
            - suffix: .XML
      - s3:
          bucket: ${self:custom.bucket}
          event: s3:ObjectCreated:*
          rules:
            - suffix: .xml
    environment:
      TOPIC_NAME: ${self:custom.snsTopicName}
```

---

<div class="post-metadata">

**Author:** ![DavidWells](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/davidwells/32/201_2.png) [@DavidWells](https://forum.serverless.com/u/DavidWells)\
**Post date:** [November 27, 2017, 7:36pm UTC](https://forum.serverless.com/t/how-to-pass-create-sns-topic-arn-to-lambda-function/3202/2 "2017-11-27T19:36:54Z")

</div>

Pass topic into the function via environment variables [https://github.com/DavidWells/serverless-workshop/blob/master/lessons-code-complete/events/sns/sns-advanced/serverless.yml#L16](https://github.com/DavidWells/serverless-workshop/blob/master/lessons-code-complete/events/sns/sns-advanced/serverless.yml#L16)

---

<div class="post-metadata">

**Author:** ![akaNightmare](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/akanightmare/32/1338_2.png) [@akaNightmare](https://forum.serverless.com/u/akaNightmare)\
**Post date:** [November 27, 2017, 8:08pm UTC](https://forum.serverless.com/t/how-to-pass-create-sns-topic-arn-to-lambda-function/3202/3 "2017-11-27T20:08:21Z")

</div>

Thanks, but according to [http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property)  
I should pass TopicARN and phone number.  
/\*\*  
\* The topic you want to publish to. If you don’t specify a value for the TopicArn parameter, you must specify a value for the PhoneNumber or TargetArn parameters.  
_/  
TopicArn?: topicARN;  
/_\*  
\* Either TopicArn or EndpointArn, but not both. If you don’t specify a value for the TargetArn parameter, you must specify a value for the PhoneNumber or TopicArn parameters.  
\*/  
TargetArn?: String;
