0
0
AWScloud~30 mins

Environment variables in Lambda in AWS - Mini Project: Build & Apply

Choose your learning style9 modes available
Environment variables in Lambda
📖 Scenario: You are building a simple AWS Lambda function that needs to use environment variables to store configuration values securely and separately from the code.This is like keeping your house keys in a safe place instead of leaving them on the door. Environment variables help your Lambda function access important settings without hardcoding them.
🎯 Goal: Create an AWS Lambda function configuration that includes environment variables. You will first define the Lambda function, then add environment variables, and finally complete the configuration to deploy the Lambda function with these variables.
📋 What You'll Learn
Create a Lambda function resource with a name MyLambdaFunction.
Add an environment variables block with two variables: STAGE set to dev and LOG_LEVEL set to info.
Complete the Lambda function configuration with a runtime and handler.
💡 Why This Matters
🌍 Real World
Environment variables in Lambda functions allow you to separate configuration from code, making your functions more flexible and secure.
💼 Career
Knowing how to configure environment variables in Lambda is essential for cloud developers and DevOps engineers managing serverless applications.
Progress0 / 4 steps
1
Create the Lambda function resource
Create a resource block for an AWS Lambda function named MyLambdaFunction using AWS CloudFormation syntax.
AWS
Need a hint?

Start by defining the Resources section and add a resource named MyLambdaFunction with type AWS::Lambda::Function.

2
Add environment variables block
Inside the MyLambdaFunction resource, add a property called Environment with a nested Variables map containing STAGE set to dev and LOG_LEVEL set to info.
AWS
Need a hint?

Use the Properties section to add Environment and then Variables with the two key-value pairs.

3
Add runtime and handler properties
Add the Runtime property set to python3.12 and the Handler property set to index.handler inside the Properties of MyLambdaFunction.
AWS
Need a hint?

Remember to add Runtime and Handler at the same level as Environment inside Properties.

4
Complete the Lambda function configuration
Add a Role property with the value arn:aws:iam::123456789012:role/lambda-execution-role inside the Properties of MyLambdaFunction to complete the configuration.
AWS
Need a hint?

The Role property is required for Lambda to have permission to run. Add it inside Properties.