I'm having an issue getting the ARN of an SQS topic passed via an environment variable to a lambda using python runtime.
Here is the relevant part of the cloud formation yaml:
HandlerFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: xxx/
Handler: app.handler
Runtime: python3.8
Timeout: 60
...
Environment:
Variables:
SNS_TOPIC_ARN: !Ref EmailNotificationTopic
EmailNotificationTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint: [email protected]
Protocol: email
Inside my handler when I call sns_topic = os.environ['SNS_TOPIC_ARN']
I get EmailNotificationTopic
instead of the full ARN, which is what I would expect from the docs.
This is creating a problem when publishing the topic. I know I can hardcode the ARN but other tutorials (and the official docs) seem to indicate the Ref function should be giving the ARN.
I'm pretty new to cloud formation, any advice is appreciated. Thank you
Edit: I added the !Ref EmailNotificationTopic to output in the sam template and confirmed it is displayed as the full ARN, I also confirmed in the topic on the AWS console the full ARN is there, so it seems like when the environment variable is being passed/read in python everything is stripped except for the last bit after the last :? Anyone know how to overcome this?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…