aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

event.stageVariables are always null

Open xentek opened this issue 8 years ago • 7 comments

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#L377
  • sam local invoke https://github.com/awslabs/aws-sam-cli/blob/9dcd0bc040b0b9c61d7b61cf36748d25de5ec0e5/samcli/commands/local/lib/events.py#L296

I 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 avatar Jun 01 '18 19:06 xentek

@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?

jfuss avatar Jun 21 '18 16:06 jfuss

I also need stage-variables to be parsed

fkmare avatar Jun 22 '18 01:06 fkmare

@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 avatar Jun 28 '18 18:06 xentek

@xentek What did you do for the workaround?

dalippa avatar Jan 08 '19 01:01 dalippa

Any update on this? Or current workaround?

kyler-hyuna avatar Jan 31 '19 17:01 kyler-hyuna

@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.

xentek avatar Feb 01 '19 17:02 xentek

Release in v0.21.0.

Closing

jfuss avatar Sep 16 '19 16:09 jfuss