support for stage variables in lambda and https integration
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
## :question: General Issue
### How to pass a stage variable to lambda function field in API Gateway?
I have an API Gateway that triggers a lambda function specified by a stage variable `stageVariables.lbfunc`.

How can I create this API Gateway with AWS CDK?
It looks like that I should create a special `handler` for [LambdaRestApi](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-apigateway.LambdaRestApi.html).
But I can't find any example code for doing this.
The following is my current code. I wish that `LambdaIntegration`'s handler can be determined by a stage variable.
```
# dev_lambda_function should be replaced by something else
dev_lambda_function = lambda_.Function(self, "MyServiceHandler",
runtime=lambda_.Runtime.PYTHON_3_7,
code=lambda_.Code.asset("resources"),
handler="lambda_function.lambda_handler",
description="My dev lambda function"
)
stage_options = apigateway.StageOptions(stage_name="dev",
description="dev environment",
variables=dict(lbfunc="my-func-dev")
)
# What should I pass to the handler variable so that LambdaRestApi triggers the lambda function specified by the stage variable "stageVariables.lbfunc"?
api = apigateway.LambdaRestApi(self, "my-api",
rest_api_name="My Service",
description="My Service API Gateway",
handler=dev_lambda_function,
deploy_options=stage_options)
```
### Environment
- **CDK CLI Version:** 1.22.0 (build 309ac1b)
- **Module Version:**
- **OS:** OSX Mojave
- **Language:** Python
### Other information
Contributor guide
Research direction
Start by reading the LambdaRestApi and LambdaIntegration API documentation and the existing comment discussion. Determine whether the integration can select a Lambda target from the stageVariables.lbfunc value; done means an AWS CDK API can express this configuration and deploy an API Gateway stage that invokes the selected function.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python, typescript
- Domain
- api, backend, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100