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

feat(api-gateway): deploy RestApi to existing stage #29486

Merged
merged 7 commits into from
Apr 26, 2024

Conversation

gracelu0
Copy link
Contributor

@gracelu0 gracelu0 commented Mar 14, 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


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

@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 labels Mar 14, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team March 14, 2024 17:39
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 14, 2024
Copy link
Member

@godwingrs22 godwingrs22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left few minor comments.

@gracelu0 gracelu0 force-pushed the add-stagename-to-deployment branch from 9e74b7e to 00306b6 Compare March 15, 2024 22:34
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Mar 15, 2024
Copy link
Member

@godwingrs22 godwingrs22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments

@gracelu0 gracelu0 force-pushed the add-stagename-to-deployment branch 3 times, most recently from a6f802e to 57e12d1 Compare March 26, 2024 17:56
@gracelu0 gracelu0 force-pushed the add-stagename-to-deployment branch from 57e12d1 to 6e9fcfc Compare March 26, 2024 23:14
@godwingrs22 godwingrs22 self-assigned this Apr 17, 2024
@gracelu0 gracelu0 force-pushed the add-stagename-to-deployment branch 2 times, most recently from acf1887 to 675eac7 Compare April 23, 2024 22:30
@gracelu0 gracelu0 changed the title feat(api-gateway): add stage name to deployment feat(api-gateway): deploy RestApi to existing stage Apr 24, 2024
@gracelu0 gracelu0 force-pushed the add-stagename-to-deployment branch from d589ef3 to d0955d0 Compare April 25, 2024 23:24
@gracelu0 gracelu0 force-pushed the add-stagename-to-deployment branch from 265dbc8 to d029be0 Compare April 25, 2024 23:49
Copy link
Member

@godwingrs22 godwingrs22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @gracelu0 for your effort in implmenting this much awaited feature.

Copy link
Contributor

mergify bot commented Apr 26, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Apr 26, 2024
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 953e46d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit f0835d9 into aws:main Apr 26, 2024
12 checks passed
Copy link
Contributor

mergify bot commented Apr 26, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@leoujjawal
Copy link

leoujjawal commented May 1, 2024

Hi @godwingrs22 @gracelu0 : I am still unable to use this in CDK Python v 2.139.1

@gracelu0
Copy link
Contributor Author

gracelu0 commented May 1, 2024

Hi @godwingrs22 @gracelu0 : I am still unable to use this in CDK Python v 2.139.1

Hi @leoujjawal it looks like this didn't make it into the latest release - it should be included the next release.

@eripoll
Copy link

eripoll commented Sep 19, 2024

I have been trying to use this but to no avail. I see my resources in the resource view, I see a new deployment is active, but the stage hasn't changed.
What am I doing wrong here?

        deployment = apigw.Deployment(
            self,
            deployment_name,
            api=api,
            retain_deployments=True,
            description=description,
            stage_name= stage_name,
        )

@leoujjawal
Copy link

leoujjawal commented Sep 19, 2024

I have been trying to use this but to no avail. I see my resources in the resource view, I see a new deployment is active, but the stage hasn't changed. What am I doing wrong here?

        deployment = apigw.Deployment(
            self,
            deployment_name,
            api=api,
            retain_deployments=True,
            description=description,
            stage_name= stage_name,
        )

All you got to do is -

# Always create a new deployment
deployment = Deployment(self, str(uuid.uuid4()), api=rest_api)

v1_stage = Stage(
            self,
            "StageV1",
            stage_name="v1",
            deployment=deployment,
            logging_level=MethodLoggingLevel.INFO,
            data_trace_enabled=False,
            tracing_enabled=True,
        )

 rest_api.deployment_stage = v1_stage


Also consider adding a deopendency on the stage for the resource you are trying to create

v1_stage.node.add_dependency(users_resource)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

api-gateway: Allow to use an existent stage for deployments
5 participants