0
0
AWScloud~10 mins

Environment variables in Lambda in AWS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define an environment variable named 'STAGE' with value 'prod' in the Lambda function configuration.

AWS
Environment: {
  Variables: {
    "STAGE": [1]
  }
}
Drag options to blanks, or click blank then click option'
Aprod
B"prod"
C'prod'
DSTAGE
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the string value.
Using single quotes instead of double quotes in JSON.
2fill in blank
medium

Complete the AWS CLI command to update the Lambda function 'MyFunction' to set an environment variable 'MODE' to 'test'.

AWS
aws lambda update-function-configuration --function-name MyFunction --environment Variables=[1]
Drag options to blanks, or click blank then click option'
A{"MODE":"test"}
B"MODE=test"
C{MODE:test}
DMODE=test
Attempts:
3 left
💡 Hint
Common Mistakes
Passing environment variables as plain text without JSON formatting.
Using single quotes or missing quotes around keys or values.
3fill in blank
hard

Fix the error in the Lambda function environment variable configuration to correctly set 'API_KEY' to '12345'.

AWS
Environment: {
  Variables: {
    API_KEY: [1]
  }
}
Drag options to blanks, or click blank then click option'
A12345
B'12345'
CAPI_KEY
D"12345"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted numbers or strings in JSON environment variables.
Using single quotes instead of double quotes.
4fill in blank
hard

Fill both blanks to create a Python Lambda handler that reads environment variables 'DB_HOST' and 'DB_PORT'.

AWS
import os

def lambda_handler(event, context):
    host = os.environ.get([1])
    port = os.environ.get([2])
    return f"Connecting to {host} on port {port}"
Drag options to blanks, or click blank then click option'
A"DB_HOST"
B"DB_PORT"
CDB_HOST
DDB_PORT
Attempts:
3 left
💡 Hint
Common Mistakes
Passing variable names without quotes causing NameError.
Mixing up the variable names.
5fill in blank
hard

Fill all three blanks to define a CloudFormation snippet that sets environment variables 'ENV', 'VERSION', and 'DEBUG' for a Lambda function.

AWS
Environment:
  Variables:
    ENV: [1]
    VERSION: [2]
    DEBUG: [3]
Drag options to blanks, or click blank then click option'
A"production"
B"1.0.0"
C"false"
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted boolean false instead of string "false".
Missing quotes around version or environment name.