简体   繁体   中英

How do I code AWS Lambda env variables using SAM?

I have a SAM app which is working fine. Recently I've started using AWS lambda environment variables to remove some of the hardcoding in code. The issue here is that with the current SAM template.yaml, I need to add the AWS lambda env variables each time I deploy the app.

Part required to be coded in SAM template

When looking up SAM documentation, I see reference to variables like here but I don't think this is not the variable I'm after.

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy-globals.html

      Environment:
        Variables:
          MESSAGE: "Hello From SAM"

You are looking at env variables defined through global variables. If you want to define them for individual AWS::Lambda::Function , you should use AWS::Lambda::Function Environment .

This will allow you to define the variables for your function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM