Skip to content

Commit

Permalink
feat(api-gateway): allow configuration of deployment description (aws…
Browse files Browse the repository at this point in the history
…#21207)

----
Closes aws#20934

Motivation: Customer would like to be able to set the description per deployment. From inside their pipeline, they could get the commit hash / commit message, timestamp, custom text, and other git-related metadata that they would like to set as description.

Thanks to @TheRealAmazonKendra for help cleaning this PR up and providing some pointers on locally building the CDK. 

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
josephedward committed Aug 30, 2022
1 parent fb22fa6 commit b4d973f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ export interface RestApiBaseProps {
* @default false
*/
readonly disableExecuteApiEndpoint?: boolean;

/**
* A description of the RestApi construct.
*
* @default - 'Automatically created by the RestApi construct'
*/
readonly description?: string;
}

/**
Expand All @@ -193,12 +200,6 @@ export interface RestApiOptions extends RestApiBaseProps, ResourceOptions {
* Props to create a new instance of RestApi
*/
export interface RestApiProps extends RestApiOptions {
/**
* A description of the purpose of this API Gateway RestApi resource.
*
* @default - No description.
*/
readonly description?: string;

/**
* The list of binary media mime-types that are supported by the RestApi
Expand Down Expand Up @@ -554,7 +555,7 @@ export abstract class RestApiBase extends Resource implements IRestApi {
if (deploy) {

this._latestDeployment = new Deployment(this, 'Deployment', {
description: 'Automatically created by the RestApi construct',
description: props.description? props.description :'Automatically created by the RestApi construct',
api: this,
retainDeployments: props.retainDeployments,
});
Expand Down
32 changes: 32 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/restapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1096,4 +1096,36 @@ describe('restapi', () => {
DisableExecuteApiEndpoint: true,
});
});


describe('Description', () => {
test('description can be set', () => {
// GIVEN
const stack = new Stack();

// WHEN
const api = new apigw.RestApi(stack, 'my-api', { description: 'My API' });
api.root.addMethod('GET');

// THEN
Template.fromStack(stack).hasResourceProperties(
'AWS::ApiGateway::RestApi',
{
Description: 'My API',
});
});

test('description is not set', () => {
// GIVEN
const stack = new Stack();

// WHEN
const api = new apigw.RestApi(stack, 'my-api');
api.root.addMethod('GET');

// THEN
Template.fromStack(stack).hasResourceProperties(
'AWS::ApiGateway::RestApi', {});
});
});
});

0 comments on commit b4d973f

Please sign in to comment.