Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api-gateway: Allow to use an existent stage for deployments #25582

Closed
1 of 2 tasks
lucashfreitas opened this issue May 15, 2023 · 10 comments · Fixed by #29486, rwlxxvii/containers#124 or rwlxxvii/containers#140 · May be fixed by NOUIY/aws-solutions-constructs#99 or NOUIY/aws-solutions-constructs#101
Assignees
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1

Comments

@lucashfreitas
Copy link

Describe the feature

Ability to specify existent environments name when creating a new deployment for an API Gateway.

Currently is possible to do that bypassing cdk lib type definition using the suggestion specified here https://stackoverflow.com/questions/63950199/how-to-use-an-existing-stage-in-api-gateway-deployments-in-aws-cdk

const deployment = new apigateway.Deployment(this, "Deployment", {
      api: restApi,
    });
    //deploys an existent stage (dev, stage, prod) - 
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    (deployment as any).resource.stageName = "myStage";
    

See more information here: https://stackoverflow.com/questions/63950199/how-to-use-an-existing-stage-in-api-gateway-deployments-in-aws-cdkenvironment

Use Case

When you have a central API Gateway and multiple other APIs/resources defined in other stacks/repo, we want to be able to deploy it to an "existent" stage without having to create/replace a new one.

  1. I have a central API Gateway which has multiple resources:
    • /resource-A -> points to an external resources defined by an external Stack-A
    • /resource-B -> points to an external resources defined by an external Stack-B.

I want to be able to re deploy Stack-A and Stack-B and also create a new deployment for an existent environment - the current options on CDK Constructs doesn't allow to easily do that and suggest creating a new stage by using new Stage
as define here https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.Deployment.html.

image

Proposed Solution

A property in the deployment construct to use an existent schema (either by stageName or an IStage interface)

 const deployment = new apigateway.Deployment(this, "Deployment", {
      api: restApi,
     stageName: stageName // this extra property to utilize an existent stage 
    });
    

This is the current way of doing that and I can confirm it works:

   (deployment as any).resource.stageName = "myStage";
   

I also considered trying to assign a stage to the rest api construct, but the deployment Stage expects a Stage object and doesn't not accept IStage.

  restApi.deploymentStage = apigateway.Stage.fromStageAttributes(
     this,
     "sggg",
     {
       restApi,
       stageName: "myStage",
     }
   );

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

"aws-cdk-lib": "^2.42.1",

Environment details (OS name and version, etc.)

MacOS

@lucashfreitas lucashfreitas added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels May 15, 2023
@github-actions github-actions bot added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label May 15, 2023
@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels May 15, 2023
@pahud
Copy link
Contributor

pahud commented May 15, 2023

Yes, being allowed to deploy using the existing stage would be great! Thank you for your detailed feature request and we appreciate your PR.

@lucashfreitas
Copy link
Author

@pahud Thanks for the quick response - I am happy to help/submit a PR with a proposal to implement this :)

@Doradas0
Copy link

Any update on this? I'm also keen for this to be implemented. Is the currently agreed workaround to still bypass the typescript type of the deployment construct?

@AlexLarentis01
Copy link

Any Updates?

@DenyWatanabe
Copy link

Also eagerly waiting for this feature, currently my only option is redeploying the existing stage using the aws client which is far from ideal.

@ChrisK1982
Copy link

I would like to see this feature as well. Has there been any movement on this topic?

@msmolich
Copy link

I've also encountered a need for this feature.

@pahud
Copy link
Contributor

pahud commented Dec 26, 2023

Hello all,

Please help us prioritize this feature request by upvotes 👍 on the issue description. According to our contributing guide, any P2 issue with 20 or more +1s will be automatically upgraded from P2 to P1 and we welcome community PRs as well.

Copy link

github-actions bot commented Feb 4, 2024

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.

@github-actions github-actions bot added p1 and removed p2 labels Feb 4, 2024
@aaythapa aaythapa self-assigned this Feb 8, 2024
@gracelu0 gracelu0 assigned gracelu0 and unassigned aaythapa Feb 8, 2024
@mergify mergify bot closed this as completed in #29486 Apr 26, 2024
mergify bot pushed a commit that referenced this issue Apr 26, 2024
### Issue #

Closes #25582 .

### Reason for this change

If I have to manually create a new deployment for API gateway but want to deploy to an existing stage instead of creating a new stage, the current workaround is `(deployment as any).resource.stageName = "myStage";`

### Description of changes

Added a new property `stageName` to `Deployment`. Updated README with two new sections: `Deploying to an existing stage` and `Controlled triggering of deployments` to show how users can trigger new deployments with their latest API changes if they manually create a `Deployment` resource for RestApi. 

Since `RestApiBase` manages `Deployment` constructs, this change applies to both `SpecRestApi` and `RestApi`. 

### Description of how you validated changes

Added unit tests and integration tests. Also successfully deployed a sample app to my account where I created a stage in the API gateway console and specified the stage name in the new deployment.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment