Skip to content

Commit

Permalink
feat(api-gateway): deploy RestApi to existing stage (#29486)
Browse files Browse the repository at this point in the history
### 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*
  • Loading branch information
gracelu0 committed Apr 26, 2024
1 parent 4f1c94b commit f0835d9
Show file tree
Hide file tree
Showing 12 changed files with 681 additions and 2 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"Resources": {
"myapi4C7BF186": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Body": {
"openapi": "3.0.2",
"info": {
"version": "1.0.0",
"title": "Test API for CDK"
},
"paths": {
"/pets": {
"get": {
"summary": "Test Method",
"operationId": "testMethod",
"responses": {
"200": {
"description": "A paged array of pets",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Empty"
}
}
}
}
},
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200"
}
},
"requestTemplates": {
"application/json": "{\"statusCode\": 200}"
},
"passthroughBehavior": "when_no_match",
"type": "mock"
}
}
}
},
"components": {
"schemas": {
"Empty": {
"title": "Empty Schema",
"type": "object"
}
}
}
},
"Name": "my-api"
}
},
"MyManualDeployment92F2175C1dcdcb8f1c24d86b6090e78df1fafcd3": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Ref": "myapi4C7BF186"
},
"StageName": "myStage"
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f0835d9

Please sign in to comment.