aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

Global context is not preserved locally #1638

Closed tim-white87 closed 4 years ago

tim-white87 commented 4 years ago

Description

Not sure if this is a bug, or a feature request, but global variables are reset when running sam local start-api on each subsequent invocation.

Steps to reproduce

Declare a global variable. Modify variable. Run sam local start-api Run multiple invocations and notice that the global variable always gets reset.

Observed result

Please provide command output with --debug flag set.

Expected result

I would expect global variable context to be preserved.

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

  1. OS: MacOs
  2. sam --version: 0.30.0

Add --debug flag to command you are running

sanathkr commented 4 years ago

This is not a bug, it's by design. Local invoke tears down the container and starts a new container. It mimics Lambda "cold starts" on every invoke.

239 is a feature request to keep containers warm and thereby preserving global variables. Track the Issue for updates.