ApiGatewayLambdaEvent allows for a dict of stage_variables to be set, and defaults to None.
However, all invocations of ApiGatewayLambdaEvent do not send stage_variables, even when they have been set in the SAM template.
Examples:
sam local api-start https://github.com/awslabs/aws-sam-cli/blob/8f2c54af9a55893cf727dcd027bc0ed96862874f/samcli/local/apigw/service.py#L377sam local invoke https://github.com/awslabs/aws-sam-cli/blob/9dcd0bc040b0b9c61d7b61cf36748d25de5ec0e5/samcli/commands/local/lib/events.py#L296I dug around the code, and didn't see an obvious way to access the stage variables from parsed template where these events are being created, but would be happy to attempt a Pull Request if you can provide some direction on the best way to do so.
I can likely work around this issue for my use case, but ideally we should be able to read stage variables locally in the same way we use them on AWS API Gateway.
@xentek As of right now, we do not parse out the stage variables from the template. This is why we set the default to None. This shouldn't be difficult to add in (some reading of the template, and pipe-ing the information through).
You can read the Variables from the template in the SAMApiProvider.
Can you define stage variables in Swagger? I can't seem to find docs related to that but could have sworn you could.
Are you still up for giving this a shot?
I also need stage-variables to be parsed
@jfuss I was able to work around this, but we are just getting started with Lambda, and will likely run into this situation again.
@xentek What did you do for the workaround?
Any update on this? Or current workaround?
@dalippa -- I don't recall exactly, but I believe I structured it so that the values lived outside of the stage variables and came from the environment. We eventually adopted AppSync over APIGateway, and now just push values in with CloudFormation directly, by passing SAM cli altogether. Sorry that I could be of more help.
Release in v0.21.0.
Closing
Most helpful comment
I also need stage-variables to be parsed