question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support for stage variables in lambda and https integration

See original GitHub issue

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

image

How can I create this API Gateway 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)

Environment

  • CDK CLI Version: 1.22.0 (build 309ac1b)
  • Module Version:
  • OS: OSX Mojave
  • Language: Python

Other information

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:13
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
lava-dukanamcommented, Mar 11, 2020

Any update on this issue? We are currently blocked with this and would like to know if there are any alternative approach?

5reactions
kling-appfirecommented, Mar 11, 2020

Agree with rampatina - the inability to pass stage variables negates the ability to utilize API-GW stages as they were designed/intended to be used, forcing sub-optimal design of multiple GWs; one per stage.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting up stage variables for a REST API deployment
Stage variables are name-value pairs that you can define as configuration attributes associated with a deployment stage of a REST API.
Read more >
HTTP API Integration with lamda function and stage variable ...
I have an HTTP API with two stages dev and prod. Each stage has a stage variable 'environment', for the dev stage the...
Read more >
Stage variable with lambda - Amazon API Gateway p18
So, at a high level, how we can use the stage variables. --- Support my work: --- Patreon: https ://www.patreon.com/srcecde PayPal: ...
Read more >
Stage variables - Amazon HTTP API tutorial p16 - YouTube
AWS ECS Tutorial | Deploy a New Application from Scratch | KodeKloud · Stage variable with lambda version & alias - Amazon API...
Read more >
Working with stages for HTTP APIs - Amazon API Gateway
To use a stage variable for a Lambda function, the function must be in the same account as the API. Stage variables don't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found