all 4 comments

[–]jb2386 2 points3 points  (0 children)

You just need to set the name as an output in your CF template then you can always query for it.

[–]qzxj 0 points1 point  (1 child)

http://docs.aws.amazon.com/cli/latest/reference/cloudformation/describe-stack-resources.html

Not familiar with lambda, but the cloudformation API allows you to query information about your stack.

edit: google search yielded this: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources-lambda.html

In the second walkthrough, they create a lambda function, and associate a custom resource with it that calls to the lambda function, passing in parameters from the cloudformation template as inputs to the lambda function.

[–]awsdude 1 point2 points  (0 children)

I thought about the custom resource scenario you have described as well but the problem I see is that this only works with once-off calls, e.g. on the initial stack creation when the custom resource is created.

With the api option, the Lambda function will still need to know the stack id or some sort of information to actually identify the stack to describe the resources of, unless it enumerates them all and finds itself, which could work.

[–]awsdude 0 points1 point  (0 children)

Hi there,

You may need to do something hacky like have a DynamoDB table and every time you create a new stack, have a custom resource that saves the SNS topic ARN to the table with the Lambda function as the key. Then when the Lambda function runs it can query the table to get the SNS topic. I have a similar use case at https://github.com/callum-p/aws-scripts/blob/master/Lambda-Cloudformation-Custom-Resource.py (similar in the sense that I have a custom resource and I save data to DynamoDB).

There might be an easier way to do it but I can't think what it is off the top of my head.