Can we set the environment variable of AWS python lambda on invocation
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT
Music by Eric Matyas
https://www.soundimage.org
Track title: Cool Puzzler LoFi
--
Chapters
00:00 Can We Set The Environment Variable Of Aws Python Lambda On Invocation
00:46 Accepted Answer Score 3
01:41 Answer 2 Score 0
01:50 Thank you
--
Full question
https://stackoverflow.com/questions/6410...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #amazonwebservices #awslambda #environmentvariables
#avk47
ACCEPTED ANSWER
Score 3
Sadly you can't set the environment variables during invocation, as they are part of lambda's configuration. Thus you can use update-function-configuration API call to set their values in unpublished function only. If the function is published (i.e. it has a version) then the environment variables are immutable.
As a workaround you can store variable SERVICE_UP externally, e.g. in AWS Systems Manager Parameter Store to persist its value between invocations.
The other workaround, if your function is unpublished, would be to use AWS SDK in the function to call update-function-configuration so that the function updates its own environment variables.
For short term storage of the SERVICE_UP value, you could use AWS Lambda execution context which persists between function executions for some time. But its not permanent.
ANSWER 2
Score 0
You can use AWS param store and keep this flag there.
See https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html