'How to add environment variable to CloudFront function in CDK?
I've created an CloudFront function in CDK:
func = cloudfront.Function(
self,
"redirect",
code=cloudfront.FunctionCode.from_file(
file_path="lambda/function.js",
),
)
How can I add an environment variable to this function?
Solution 1:[1]
These are the restrictions for edge functions. Environmental Variables are clearly not supported for Lambda@Edge functions. From Cloud Formation documentation for Cloud Functions, it seems that there is no way to add environmental variables.
This is to be expected, as Cloud Functions are supposed to be lightweight functions that need to be replicated across all edges. (A normal lambda function runs in a specific region in it's own environment.)
Solution 2:[2]
Why would you need to use environment variables in this case?
Just bake the variables into the function itself.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | kgiannakakis |
Solution 2 | cigien |