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.