I have an API Gateway that triggers a lambda function specified by a stage variable stageVariables.lbfunc
.
How can I create this kind of integration request with AWS CDK?
It looks like that I should create a special handler
for LambdaRestApi.
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)