I use SLS to create a lambda function with an SNS topic event trigger:
MyFunc:
handler: ...
events:
- sns:
arn: arn:aws:sns:eu-west-1:xxxxxxxxx:some_topic-prod # from a stack variable
This renders the following in CF:
"MyFuncSnsSubscriptionSometopicprod": {
"Type": "AWS::SNS::Subscription",
"Properties": {
"TopicArn": "arn: arn:aws:sns:eu-west-1:xxxxxxxxx:some_topic-prod",
"Protocol": "lambda",
"Endpoint": {
"Fn::GetAtt": [
"MyFuncLambdaFunction",
"Arn"
]
}
}
}
Now, I need to pass the ARN of the subscription (not the topic) to my lambda function as an environment variable. How can I get a reference to this resource?
There are some tricks regarding getting the CF name of another lambda function etc which I’m already aware of (function name + “LambdaFunction”), but here it gets very ugly to reference the resource by the name generated by SLS, which seems to be Function name + “SnsSubscription” + name of SNS topic converted to titlecase and with all special characters stripped away.
Is there some clever way to either choose the name of the SNS subscription so that I can use !Ref ANameThatIChose
, or is there a plugin or something to scan the CF template for a resource matching a criteria (e.g. type: AWS::SNS::Subscription
)?
Or do I have to skip generating this event and manually create the CF for it?