Skip to content
Latchkey

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.

AWS
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

  1. Delete the Environment block from the function definition.
  2. Publish a new version without env vars.
  3. Associate that version with the CloudFront behavior.
template.yaml
# SAM/CloudFormation: remove this from the edge function
# Environment:
#   Variables:
#     STAGE: prod

Pass 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.

Frequently asked questions

What causes ""environment variables are not supported""?
The IaC or deploy that creates the function includes an Environment block, which is incompatible with Lambda@Edge association.
How do I fix "environment variables are not supported"?
Remove environment variables from the function

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card