Last active
December 6, 2018 21:50
-
-
Save cardoni/15263714d46d15b8b2be473c412da17e to your computer and use it in GitHub Desktop.
How to detect if Python script is running within AWS-ish environments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_running_in_aws_context(): | |
aws_environment_identifiers = [ | |
'AWS_LAMBDA_FUNCTION_NAME', | |
'AWS_SAM_LOCAL', | |
'LAMBDA_TASK_ROOT' | |
] | |
# check each one and return true or false | |
for env_var_id in aws_environment_identifiers: | |
env_var_value = os.getenv(env_var_id, 0) | |
# check to see if 'env_var_value' is set to some text value | |
env_var_exists_and_is_set = bool( | |
env_var_value and env_var_value.strip()) | |
if (env_var_exists_and_is_set): | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment