(api-gateway-v2): Add stage variables to HttpApi Stage
I have an HttpApi Stage that needs stage functions to call different aliases of Lambda Functions.
Also, it's supported on the RestApi Stages and should be supported for HttpApi Stages
Then also add support to stage variables for HttpApi integrations similar to #6143 but for HttpApi integrations
Use Case
I have an HttpApi Stage that needs stage functions to call different aliases of Lambda Functions.
Proposed Solution
The same way you would add stage variables to a RestApi Stage is the same way you should to an HttpApi Stage
Other
- [ ] :wave: I may be able to implement this feature request
- [ ] :warning: This feature might incur a breaking change
This is a :rocket: Feature Request
So this really havent been done right?
No wonder I didnt see the StageVariables options for me to fill in here
But in cloudformation docs, stageVariables is available as shown here
Blocked me for whole day. any solution for this?
@PoofyFoopy do you have any workaround to this??
@kenchoong not really, my workaround was to actually go into the console and add the variables. But I hope this gets added soon
@PoofyFoopy Then how you invoke the different Lambda Alias? Can you do that?
Alright, I list down all the problem I face as a record here:
-
In HttpApi contsruct, You can
add_stage(..)but you cant addstageVariablesinto the stage -
Then
add_routes()method, integration is acceptingIHttpRouteIntegrationobject as parameter, therefore you need to use one of the class inside aws_apigatewayv2_integrations which will cause the following problem:
- When using LambdaProxyIntegration, it can only accept
IFunctionas the handler. - That's means you cant invoke the LambdaAlias like
myFunction:devormyFunction:prod, it only acceptmyFunction - So thats means no matter what stage whether is
dev,prod,beta, it only will invokemyFunctiononly, all go to$Latestversion of the function. - Thought to use
HttpProxyIntegration, so I can invoke the lambda like this(as stated here):
# invoke the lambda function via a URI, with POST method
api_uri = (
f"arn:aws:apigateway:"
f"{cdk.Aws.REGION}"
f":lambda:path/2015-03-31/functions/"
f"{function.function_arn}"
f":"
f"${{stageVariables.lambdaAlias}}"
f"/invocations"
)
No you cant do that, cause HttpProxyIntegration only accept a Http url. Not this Lambda Uri.
- Then I tot to use
HttpIntegrationfor the route integration. No, you cant do that as well, cause remember?addRoutes()only acceptIHttpRouteIntegration, but HttpIntegration isIHttpIntegration, is 2 different thing.
Beside, HttpIntegration is the integration for the whole HttpApi, which all the different route, also will use the same Integration,this is what I tried:
# try to invoke different lambdaAlias
stage_lambda_id = function.node.id + "LambdaStageIntegration"
stage_function_arn = (
f"{function.function_arn}"
f":"
f"${{stageVariables.lambdaAlias}}"
)
# then wanna use it in the HttpIntegration
my_integration = apigateway.HttpIntegration(
self, stage_lambda_id,
http_api=api, # this is mandatory, will plug in the whole API to use this integration, so all go to same `lambda`
integration_type=apigateway.HttpIntegrationType.LAMBDA_PROXY,
integration_uri=stage_function_arn
)
# but the integration,cant use it per route, only for whole API
user_route_list = api.add_routes(
path="/user",
methods=api_methods_list,
authorizer=some_authorizer,
integration=my_integration # u cant use it here, because it only accept IHttpRouteIntegration
)
Alright, all this is what I tried, conclusion is:
- HttpApi cant add in StageVariables into each stage
- HttpApi cant invoke different Lambda Alias according to stageVariable for each stage
- HttpApi only can 1 route invoke 1 Lambda Version which is $Latest (cause it cant invoke different alias, therefore only $Latest)
1 thing I like about HttpApi is: The build in JWT authorizer. This is very good! Save me a lot of time from writing it myself.
But look like it scarified all the other benefit of RestAPI.
Just my little opinion, I hope this can fix soon. I need to move on from this now
Any news about this feature please? Thank you!
We also would very much like to utilise this feature!
Can the CDK seriously not create stage variables for a HTTP api? We want to set a stage variable (on our default/only stage) for a "JWT Audience" that a common lambda request authorizer uses, as a parameter. (and no, your builtin jwt authorizer won't work for us, it doesn't support Cloudflare Zero Trust).
e.g. httpapi.defaultStage.stagevariables["audience"] = "123456789"
our workaround right now is to add this manually in the web console.
Hi there, is there anything that can be done to help prioritize this feature?
My team has just run into this obstacle. I see that this has been open for 2 years and that someone marked it as "low effort". We could really use it. Thanks!
I've just come across this same issue.
It's been three years, when can I use stage variables in the integration uri? Is there any alternative way to do so?
This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.
Same issue I ran into, wasted a good few hours until I stumbled on this. Any updates will help.
Quick overview solutions:
- custom cloud formation escape hatch to setup the url
- manually create those stage variables via console or aws cli script
- use different gateways per env.
Any update on this issue? I still cannot see the option to add stage variables
This issue still hasnt been fixed, have to create a CfnStage and CfnApiMapping in order to achieve the same result.
After 4 years, it is not natively supported yet?
has this been implemented yet?
Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.