Skip to content

Commit

Permalink
update README and integ test
Browse files Browse the repository at this point in the history
  • Loading branch information
gracelu0 committed Mar 26, 2024
1 parent 00306b6 commit 6e9fcfc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.

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
Expand Up @@ -25,7 +25,7 @@
}
}
},
"MyManualDeployment92F2175C6f3141cef1e8fea8ab3b3b8bc90df36d": {
"MyManualDeployment92F2175C35a2644115e0765ad867f11b599a51c1": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand Down

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
Expand Up @@ -5,17 +5,22 @@ import * as integ from '@aws-cdk/integ-tests-alpha';
const app = new cdk.App();
const stack = new cdk.Stack(app, 'integtest-restapi-import-deployment-stage');

// Set deploy to false so RestApi does not automatically create a Deployment
const api = new apigateway.RestApi(stack, 'my-api', {
retainDeployments: true,
deploy: false,
});
api.root.addMethod('GET');

// Create a new deployment that uses existing stage
new apigateway.Deployment(stack, 'MyManualDeployment', {
// Manually create a deployment that deploys to an existing stage
const deployment = new apigateway.Deployment(stack, 'MyManualDeployment', {
api: api,
stageName: 'myStage',
});

// Generate a new logical ID so the deployment reflects changes made to api
deployment.addToLogicalId(`Deployment-${Date.now()}`);

new integ.IntegTest(app, 'restapi-import-deployment-stage', {
testCases: [stack],
});
Expand Down
10 changes: 9 additions & 1 deletion packages/aws-cdk-lib/aws-apigateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -997,19 +997,27 @@ const api = new apigateway.RestApi(this, 'books', {
```
### Deploying to an existing stage

If you want to use an existing stage for a deployment, you can specify the stage name in the deployment as follows:
If you want to use an existing stage for a deployment, first set `{ deploy: false }` so that `RestApi` does not automatically create new `Deployment` and `Stage` resources. Then you can manually define a `apigateway.Deployment` resource and specify the stage name for your existing stage using the `stageName` property.

Note that as long as the deployment's logical ID doesn't change, it will represent the snapshot in time when the resource was created. To ensure your deployment reflects changes to the `RestApi` model, use the method `addToLogicalId(data)` to augment the logical ID generated for the deployment resource.
```ts
const restApi = new apigateway.RestApi(this, 'my-api', {
deploy: false,
});

// Use `stageName` to deploy to an existing stage
const deployment = new apigateway.Deployment(this, 'my-deployment', {
api: restApi,
stageName: 'dev',
});

// Generate a new logical ID so the deployment reflects changes made to api
deployment.addToLogicalId(`Deployment-${Date.now()}`);

```

If the `stageName` property is set but a stage with the corresponding name does not exist, a new stage
resource will be created with the provided stage name.

### Deep dive: Invalidation of deployments

Expand Down
9 changes: 5 additions & 4 deletions packages/aws-cdk-lib/aws-apigateway/lib/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export interface DeploymentProps {
/**
* The name of the stage the API Gateway deployment deploys to.
*
* @default - No stage name.
* @default - No stage name. If the `stageName` property is set but a stage with the
* corresponding name does not exist, a new stage resource will be created with the
* provided stage name.
*/
readonly stageName?: string;
}
Expand Down Expand Up @@ -69,10 +71,9 @@ export class Deployment extends Resource {
/** @attribute */
public readonly deploymentId: string;
public readonly api: IRestApi;

/**
* The stage of the API Gateway deployment.
*/
* The stage of the API gateway deployment.
*/
public readonly stageName?: string;

private readonly resource: LatestDeploymentResource;
Expand Down

0 comments on commit 6e9fcfc

Please sign in to comment.