Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does zappa upload environment variables to?

tl;dr

Environment variables set in a zappa_settings.json don't upload as environment variables to AWS Lambda. Where do they go?

ts;wm

I have a Lambda function configured, deployed and managed using the Zappa framework. In the zappa_settings.json I have set a number of environment variables. These variables are definitely present as my application successfully runs however, when trying to inspect the Lambda function environment variables in the console or AWS CLI I see no environment variables have been uploaded to the Lambda function itself.

Extract from zappa_settings.json:

{
  "stage-dev": {
    "app_function": "project.app",
    "project_name": "my-project",
    "runtime": "python3.7",
    "s3_bucket": "my-project-zappa",
    "slim_handler": true,
    "environment_variables": {
      "SECRET": "mysecretvalue"
    }
  }
}

Output of aws lambda get-function-configuration --function-name my-project-stage-dev:

{
  "Configuration": {
    "FunctionName": "my-project-stage-dev",
    "FunctionArn": "arn:aws:lambda:eu-west-1:000000000000:function:my-project-stage-dev",
    "Runtime": "python3.7",
    "Role": "arn:aws:iam::000000000000:role/lambda-execution-role",
    "Handler": "handler.lambda_handler",
    "CodeSize": 12333025,
    "Description": "Zappa Deployment",
    "Timeout": 30,
    "MemorySize": 512,
    "LastModified": "...",
    "CodeSha256": "...",
    "Version": "$LATEST",
    "TracingConfig": {
      "Mode": "PassThrough"
    },
    "RevisionId": "..."
  },
  "Code": {
    "RepositoryType": "S3",
    "Location": "..."
  }
}

Environment is absent from the output despite being included in the zappa_settings and the AWS documentation indicating it should be included if present, this is confirmed by checking in the console. I want to know where zappa is uploading the environment variables to, and if possible why it is doing so over using Lambda's in-built environment?

AWS CLI docs: https://docs.aws.amazon.com/cli/latest/reference/lambda/get-function-configuration.html

like image 294
Josh Avatar asked Feb 13 '20 10:02

Josh


People also ask

Where do I put environment variables?

On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable.

How do I set environment variables in environ?

With the environ dictionary variable value of the environment variable can be set by passing the key in the dictionary and assigning the value to it. With setdefault a default value can be assigned to the environment variable. Bypassing the key and the default value in the setdefault method.

How do you manage environment variables?

There are multiple solutions: you ask each developer to set the value in their environment before launching the application. you add some logic at the application's initialization to use the API key environment variable value if it exists, otherwise, fall back to the plain configuration file.


1 Answers

environment_variables are saved in zappa_settings.py when creating a package for deployment (run zappa package STAGE and explore the archive) and are then dynamically set as environment variables by modifying os.environ in handler.py.

To set native AWS variables you need to use aws_environment_variables.

like image 161
tmt Avatar answered Nov 01 '22 10:11

tmt