Skip to content

Commit f0835d9

Browse files
authored
feat(api-gateway): deploy RestApi to existing stage (#29486)
### 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*
1 parent 4f1c94b commit f0835d9

12 files changed

+681
-2
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/integ.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/integtest-specrestapi-import-deployment-stage.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"Resources": {
3+
"myapi4C7BF186": {
4+
"Type": "AWS::ApiGateway::RestApi",
5+
"Properties": {
6+
"Body": {
7+
"openapi": "3.0.2",
8+
"info": {
9+
"version": "1.0.0",
10+
"title": "Test API for CDK"
11+
},
12+
"paths": {
13+
"/pets": {
14+
"get": {
15+
"summary": "Test Method",
16+
"operationId": "testMethod",
17+
"responses": {
18+
"200": {
19+
"description": "A paged array of pets",
20+
"content": {
21+
"application/json": {
22+
"schema": {
23+
"$ref": "#/components/schemas/Empty"
24+
}
25+
}
26+
}
27+
}
28+
},
29+
"x-amazon-apigateway-integration": {
30+
"responses": {
31+
"default": {
32+
"statusCode": "200"
33+
}
34+
},
35+
"requestTemplates": {
36+
"application/json": "{\"statusCode\": 200}"
37+
},
38+
"passthroughBehavior": "when_no_match",
39+
"type": "mock"
40+
}
41+
}
42+
}
43+
},
44+
"components": {
45+
"schemas": {
46+
"Empty": {
47+
"title": "Empty Schema",
48+
"type": "object"
49+
}
50+
}
51+
}
52+
},
53+
"Name": "my-api"
54+
}
55+
},
56+
"MyManualDeployment92F2175C1dcdcb8f1c24d86b6090e78df1fafcd3": {
57+
"Type": "AWS::ApiGateway::Deployment",
58+
"Properties": {
59+
"RestApiId": {
60+
"Ref": "myapi4C7BF186"
61+
},
62+
"StageName": "myStage"
63+
}
64+
}
65+
},
66+
"Parameters": {
67+
"BootstrapVersion": {
68+
"Type": "AWS::SSM::Parameter::Value<String>",
69+
"Default": "/cdk-bootstrap/hnb659fds/version",
70+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
71+
}
72+
},
73+
"Rules": {
74+
"CheckBootstrapVersion": {
75+
"Assertions": [
76+
{
77+
"Assert": {
78+
"Fn::Not": [
79+
{
80+
"Fn::Contains": [
81+
[
82+
"1",
83+
"2",
84+
"3",
85+
"4",
86+
"5"
87+
],
88+
{
89+
"Ref": "BootstrapVersion"
90+
}
91+
]
92+
}
93+
]
94+
},
95+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
96+
}
97+
]
98+
}
99+
}
100+
}

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/manifest.json

+119
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)