Lambda@Edge "environment variables are not supported" in CI
Lambda@Edge functions cannot use Lambda environment variables. If a function version has env vars set, the CloudFront association fails. Configuration must be baked into the code or fetched at runtime instead.
What this error means
Associating the function with CloudFront fails with "The function cannot have environment variables. Lambda@Edge does not support environment variables." even though a regular Lambda would accept them.
An error occurred (InvalidLambdaFunctionAssociation) when calling the
UpdateDistribution operation: The function cannot have environment variables.
Lambda@Edge does not support environment variables.Common causes
The function definition sets Environment variables
The IaC or deploy that creates the function includes an Environment block, which is incompatible with Lambda@Edge association.
A shared template reused from a regional Lambda
A template written for a normal Lambda carries env vars that must be removed for the edge variant.
How to fix it
Remove environment variables from the function
- Delete the Environment block from the function definition.
- Publish a new version without env vars.
- Associate that version with the CloudFront behavior.
# SAM/CloudFormation: remove this from the edge function
# Environment:
# Variables:
# STAGE: prodPass configuration another way
Bake constants into the bundle at build time, or fetch configuration at runtime from a store the function can reach.
How to prevent it
- Keep Lambda@Edge function templates free of environment variables.
- Inject config at build time or fetch it at runtime.
- Do not reuse a regional Lambda template verbatim for an edge function.