3.4.10 Runtime Configurations for Dynamic Deployments

Use Runtime Configurations for Dynamic Deployments

API Gateway Stage Variables → Lambda

Stage: prod
  Variables:
    lambdaAlias: prod
    tableName: orders-prod

Lambda ARN: arn:aws:lambda:region:account:function:my-func:${stageVariables.lambdaAlias}

Lambda Environment Variables

import os

TABLE_NAME = os.environ['TABLE_NAME']    # orders-prod
STAGE = os.environ.get('STAGE', 'dev')   # prod
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO')

Parameter Store for Runtime Config

import boto3

ssm = boto3.client('ssm')
response = ssm.get_parameter(
    Name=f'/myapp/{os.environ["STAGE"]}/feature-flag',
    WithDecryption=True
)
feature_enabled = response['Parameter']['Value'] == 'true'

AppConfig for Feature Flags

import urllib.request
import json

# AppConfig Lambda extension
url = 'http://localhost:2772/applications/MyApp/environments/prod/configurations/Features'
config = json.loads(urllib.request.urlopen(url).read())

Exam Tip: Stage variables for API GW → Lambda dynamic routing. Env vars for static config. Parameter Store/AppConfig for runtime config changes without redeployment.