2

When running functions in AWS lambda, it's common to use environment variables to control settings. However, when invoking Lambda via API gateway you have 'stage variables' to contend with.

My question is this: is an AWS Lambda instance scoped to a particular API gateway stage when invoked from API gateway, such that I can rely on the stage not changing between calls. In effect, does each API 'stage' get it's own pool of instances to work with, which are recycled in accordance with stage variables?

Examples of where I might want to depend on this behaviour:

  • Creating connections to tables - the table name will be different per-stage, so if I create the connection on first usage I'd end up using the first callers stage context. What happens when I make a call on a different API gateway stage?

  • Varying JWT keys for environments.

My gut feeling on this is that if API gateway has two versions/stages of the deployment referencing the exact same function verison, the lambda-managed function instances can recieve calls from two stages interchangably, and I shoulnd't cache the context and request derrived information (stage-variables) variables in process.

There's a lot of AWS API Gateway / Lambda stuff out there, but couldn't find a clear answer to this issue.

1 Answer 1

1

You're right, a single Lambda function version will have a pool of instances that are totally independent. Different API Gateway stages and even different APIs can call the same function and this has no impact on the instance pool in Lambda.

So any in-function caching you're doing should not use the assumption that only a specific API and/or stage will access the cached data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.