question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`local start-api --container-env-vars` option does not work

See original GitHub issue

Description:

It is not clear (to me) what --container-env-vars does when used with sam local start-api.

My understanding is that it should set environment variable to underlying docker container which runs lambda (of PackageType::Zip) in sam local environment without having that environment variable defined in template.yaml

when I run:

sam local start-api --container-env-vars sam_local_envs.json --warm-containers EAGER

sam does not set environment variables to container it starts.

Also, it is not clear what kind the format that file should have, is it same format like --env-vars ?

Steps to reproduce:

sam local start-api --container-env-vars sam_local_envs.json --warm-containers EAGER

where sam_local_envs.json is defined like (hoping that at least one key will work) :

{
    "P1": "V1",
    "Parameters": {
        "P2": "V2",
    }
}

function part of template.yaml is something like:

  LambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: bootstrap
      Runtime: provided.al2
      CodeUri: .
      Events:
        HelloApi:
          Type: Api
          Properties:
            Path: /{path_param}
            Method: get
            RestApiId:
              Ref: ApiGatewayApi
    Metadata:
      BuildMethod: makefile

Observed result:

docker inspect of container which sam started returns:

          "Env": [
              "AWS_SAM_LOCAL=true",
              "AWS_LAMBDA_FUNCTION_MEMORY_SIZE=128",
              "AWS_LAMBDA_FUNCTION_TIMEOUT=10",
              "AWS_LAMBDA_FUNCTION_HANDLER=bootstrap",
              "AWS_LAMBDA_FUNCTION_NAME=[REDACTED]",
              "AWS_LAMBDA_FUNCTION_VERSION=$LATEST",
              "AWS_LAMBDA_LOG_GROUP_NAME=aws/lambda/[REDACTED]",
              "AWS_LAMBDA_LOG_STREAM_NAME=$LATEST",
              "AWS_REGION=us-east-1",
              "AWS_DEFAULT_REGION=us-east-1",
              "AWS_ACCESS_KEY_ID=[REDACTED]",
              "AWS_SECRET_ACCESS_KEY=[REDACTED]",
              "AWS_ACCOUNT_ID=[REDACTED]",
              "RUST_BACKTRACE=1",
              "RUST_LOG=trace",
              "LANG=en_US.UTF-8",
              "TZ=:/etc/localtime",
              "PATH=/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin",
              "LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib",
              "LAMBDA_TASK_ROOT=/var/task",
              "LAMBDA_RUNTIME_DIR=/var/runtime"
          ],

Expected result:

environment variables which exists in --container-env-vars file should be set in container

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: MacOS
  2. sam --version: SAM CLI, version 1.43.0
  3. AWS region:

Add --debug flag to command you are running

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
qingchmcommented, Apr 11, 2022

Thanks for your detailed feedback! Let me take a look at this more closely!

0reactions
milenkovicmcommented, Sep 13, 2022

thanks @madeupname, that would be one way i know, but that would not preferred way as I wouldn’t like debug related options on configuration which may go to production. if there is an option, someone can flip it 😃

but anyhow, it does not look that this issue is going anywhere anytime soon

Read more comments on GitHub >

github_iconTop Results From Across the Web

sam local start-api - AWS Serverless Application Model
Pass environment variables to image container when locally debugging. The log file to send runtime logs to. Specifies the location basedir where the...
Read more >
Container environment variables - Visual Studio Code
Use environment variables in containers. ... As this example illustrates, containerEnv can reference local variables and remoteEnv can reference both local ...
Read more >
sam local start-api - Amazon Serverless Application Model
Pass environment variables to image container when locally debugging. The log file to send runtime logs to. Specifies the location basedir where the...
Read more >
Environment variables in Compose | Docker Documentation
The .env file feature only works when you use the docker-compose up command and does not work with docker stack deploy . Both...
Read more >
aws-sam-local environment variables - Stack Overflow
It does not work as a mechanism to inject arbitrary environment ... when you run sam local start-api --env-vars env.json and it will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found