0

I'm new to the aws serverless world and I have the following simple system:

  • an input queue which invoke a lambda for each input it has
  • the lambda do some work on that input and then push it into an output queue

My question is how can i get the output queue url/physical name?

I found 2 solutions so far:

  1. pass it by env variable in the cloudformation template.yml file. The con is that I have to provide this env variable every time. And in complex system there are a lot such variables. Thats feels fishy to me.
  2. use boto3.resource('cloudformation').StackResource(stack name, resource name).physical_resource_id. The con is that I hard coded the template structure in my code.

What is the correct solution?

MyNick
  • 536
  • 1
  • 9
  • 25

2 Answers2

2

You can use AWS Systems Manager Parameter Store to store the queue name as an AWS::SSM::Parameter resource and retrieve it from the Lambda function. Here’s an example using a secure string, but you can do the same with clear text parameters.

Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
1

Keep a json file with lambda having all the constants.

Pros.

  • Easy to read and low latency.
  • Can hold large number of constants in a nested structure.
Chandan Kumar
  • 1,066
  • 10
  • 16
  • Can I include values from it in the template.yaml file? If so, how can I do it? – MyNick Jul 24 '20 at 09:01
  • https://stackoverflow.com/questions/1773805/how-can-i-parse-a-yaml-file-in-python. – Chandan Kumar Jul 24 '20 at 09:14
  • So your suggestion is editing the `template.yml` file and specify the constants in it. Then create a new template yml file and deploy it? – MyNick Jul 24 '20 at 09:31
  • In the lambda code keep a yml or json file with constants like queue url and in the lambda code read that constants. Now you don't have to keep the url in template file anymore. – Chandan Kumar Jul 24 '20 at 10:30