4

I'm trying to create a lambda function associate with an API Gateway.

A new lambda version for that function will be created whenever new version is deployed, this version will have this ARN arn:lambda_arn:[version].

Also a new API Gateway stage need to be created with integration with that lambda version.

When I deploy the CF stack :

  • Create new lambda version
  • Create API Gateway stage that's integrated with that version of lambda
  • Create API Gateway stage called dev that's integrated with the lambda alias dev (arn:lambda:dev) and keep this stage where the alias is managen manually from the lambda settings.

I've already tried to achieve this using sam cli yaml template and also with aws cdk, but here's the issues I faced:

Can't create multiple API Gateway Stages with different integrations, keeping the old stages

  • In cdk I can only create the HttpApi once
http_api = apigwv2.HttpApi(self, "cdk_http_api")

Even though I can create multiple stages for that HttpApi, but all stages will have the exact same integration and routes.

Creating a deployment would be useful, but even though I can't create different deployments with different integrations (that uses different version of lambda)

deployment = apigwv2.CfnDeployment(
    self, "first_deployment", api_id=http_api.api_id, stage_name="test"
)

Also I can't attach it to a stage! unlike ApiGatewayV1 as mentioned below

The newly created stage will remove the old stages, I can't append new stages

Lambda version is being removed:

  • In cdk, when I deploy a new lambda version the previous lambda version is getting removed.

  • In Sam CLI when I set the AutoPublishAlias property to the function, a new version get created and the specified alias will shifted to that new version, but fortunately it won't remove the older version.

How can I achieve what I want

Not Duplicate of this answer as it uses ApiGatewayV1 which supports deployments, where ApiGatewayV2 doesn't support unfortunately.

Amer Sawan
  • 2,126
  • 1
  • 22
  • 40

0 Answers0