Enhance SAM with features tailored to your specific needs! We collaborate with companies, universities, and organizations to privately fund new capabilities or analyses. Your investment drives innovation while benefiting the broader energy community. Email us to learn more.

AWS SAM Template - Defining Environment Variables for Lambda Function

  • Vishal
  • Topic Author
More
14 Aug 2023 02:47 #12413 by Vishal
I'm working on an AWS Serverless Application Model (SAM) project and I'm trying to define environment variables for my Lambda function within the
Code:
template.yaml
file. I want to set specific configuration values that my Lambda function can access at runtime.I've looked through the AWS SAM documentation, but I'm having trouble finding a clear example of how to define environment variables directly in the template.Could someone provide guidance on the proper syntax and structure to define environment variables for a Lambda function using AWS SAM? Are there any best practices or considerations I should be aware of when setting up environment variables within the SAM template?Here's a snippet of what I have so far:
Code:
Resources:   MyLambdaFunction:     Type: AWS::Serverless::Function     Properties:       CodeUri: ./my-lambda-code       Handler: index.handler       Runtime: nodejs14.x       Environment:         Variables:           MY_CONFIG_KEY: "my-config-value"

Is this the correct approach, or am I missing something? Any help would be greatly appreciated. Thank you!

Please Log in or Create an account to join the conversation.

  • Paul Gilman
More
14 Aug 2023 10:11 #12416 by Paul Gilman
Hi Vishal,

Wrong SAM! This is a forum for NREL's System Advisor Model (SAM).

For the AWS Serverless Application Model (SAM), see aws.amazon.com/serverless/sam/ .

Best regards,
Paul.

Please Log in or Create an account to join the conversation.

Moderators: Paul Gilman
Powered by Kunena Forum