Skip to content

Commit

Permalink
Merge branch 'master' into dynamodb-aws-sdk-no-install
Browse files Browse the repository at this point in the history
  • Loading branch information
jogold authored Apr 23, 2020
2 parents 9c956c6 + 98429e0 commit 2209bf7
Show file tree
Hide file tree
Showing 143 changed files with 5,389 additions and 1,123 deletions.
3 changes: 2 additions & 1 deletion pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ rm -fr ${distdir}
mkdir -p ${distdir}

# Split out jsii and non-jsii packages. Jsii packages will be built all at once.
# Non-jsii packages will be run individually.
# Non-jsii packages will be run individually. Note that currently the monoCDK
# package is handled as non-jsii because of the way it is packaged.
echo "Collecting package list..." >&2
scripts/list-packages $TMPDIR/jsii.txt $TMPDIR/nonjsii.txt

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"devDependencies": {
"conventional-changelog-cli": "^2.0.31",
"fs-extra": "^8.1.0",
"jsii-diff": "^1.3.2",
"jsii-pacmak": "^1.3.2",
"jsii-rosetta": "^1.3.2",
"jsii-diff": "^1.4.1",
"jsii-pacmak": "^1.4.1",
"jsii-rosetta": "^1.4.1",
"lerna": "^3.20.2",
"standard-version": "^7.1.0",
"typescript": "~3.8.3"
Expand Down
25 changes: 21 additions & 4 deletions packages/@aws-cdk/aws-apigateway/lib/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CfnResource, Construct, Lazy, RemovalPolicy, Resource, Stack } from '@aws-cdk/core';
import * as crypto from 'crypto';
import { CfnDeployment, CfnDeploymentProps } from './apigateway.generated';
import { CfnDeployment } from './apigateway.generated';
import { IRestApi, RestApi } from './restapi';

export interface DeploymentProps {
Expand Down Expand Up @@ -68,7 +68,7 @@ export class Deployment extends Resource {

this.resource = new LatestDeploymentResource(this, 'Resource', {
description: props.description,
restApiId: props.api.restApiId,
restApi: props.api,
});

if (props.retainDeployments) {
Expand Down Expand Up @@ -116,13 +116,23 @@ export class Deployment extends Resource {
}
}

interface LatestDeploymentResourceProps {
readonly description?: string;
readonly restApi: IRestApi;
}

class LatestDeploymentResource extends CfnDeployment {
private hashComponents = new Array<any>();
private originalLogicalId: string;
private api: IRestApi;

constructor(scope: Construct, id: string, props: CfnDeploymentProps) {
super(scope, id, props);
constructor(scope: Construct, id: string, props: LatestDeploymentResourceProps) {
super(scope, id, {
description: props.description,
restApiId: props.restApi.restApiId,
});

this.api = props.restApi;
this.originalLogicalId = Stack.of(this).getLogicalId(this);
}

Expand All @@ -145,6 +155,13 @@ class LatestDeploymentResource extends CfnDeployment {
* add via `addToLogicalId`.
*/
protected prepare() {
if (this.api instanceof RestApi) { // Ignore IRestApi that are imported

// Add CfnRestApi to the logical id so a new deployment is triggered when any of its properties change.
const cfnRestApiCF = (this.api.node.defaultChild as any)._toCloudFormation();
this.addToLogicalId(Stack.of(this).resolve(cfnRestApiCF));
}

const stack = Stack.of(this);

// if hash components were added to the deployment, we use them to calculate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"Name": "MyRestApi"
}
},
"MyRestApiDeploymentB555B5828fad37a0e56bbac79ae37ae990881dca": {
"MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand All @@ -150,7 +150,7 @@
"Ref": "MyRestApi2D1F47A9"
},
"DeploymentId": {
"Ref": "MyRestApiDeploymentB555B5828fad37a0e56bbac79ae37ae990881dca"
"Ref": "MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb"
},
"StageName": "prod"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
"Name": "MyRestApi"
}
},
"MyRestApiDeploymentB555B5828fad37a0e56bbac79ae37ae990881dca": {
"MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand All @@ -189,7 +189,7 @@
"Ref": "MyRestApi2D1F47A9"
},
"DeploymentId": {
"Ref": "MyRestApiDeploymentB555B5828fad37a0e56bbac79ae37ae990881dca"
"Ref": "MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb"
},
"StageName": "prod"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"Name": "MyRestApi"
}
},
"MyRestApiDeploymentB555B5828fad37a0e56bbac79ae37ae990881dca": {
"MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand All @@ -150,7 +150,7 @@
"Ref": "MyRestApi2D1F47A9"
},
"DeploymentId": {
"Ref": "MyRestApiDeploymentB555B5828fad37a0e56bbac79ae37ae990881dca"
"Ref": "MyRestApiDeploymentB555B582dcff966d69deeda8d47e3bf409ce29cb"
},
"StageName": "prod"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Name": "cors-api-test"
}
},
"corsapitestDeployment2BF1633A197b7a426736ab40a59d8a41c2d3d50d": {
"corsapitestDeployment2BF1633A228079ea05e5799220dd4ca13512b92d": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand All @@ -29,7 +29,7 @@
"Ref": "corsapitest8682546E"
},
"DeploymentId": {
"Ref": "corsapitestDeployment2BF1633A197b7a426736ab40a59d8a41c2d3d50d"
"Ref": "corsapitestDeployment2BF1633A228079ea05e5799220dd4ca13512b92d"
},
"StageName": "prod"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
}
}
},
"deployment33381975": {
"deployment3338197541aef5f15bf9a60b10e06fdbe72854f4": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand All @@ -374,7 +374,7 @@
"Ref": "lambdarestapiF559E4F2"
},
"DeploymentId": {
"Ref": "deployment33381975"
"Ref": "deployment3338197541aef5f15bf9a60b10e06fdbe72854f4"
},
"StageName": "prod"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"Name": "books-api"
}
},
"booksapiDeployment308B08F1c828b08824c062376eba921738884f85": {
"booksapiDeployment308B08F132cc25cf8168bd5e99b9e6d4915866b5": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand All @@ -181,7 +181,7 @@
"Ref": "booksapiE1885304"
},
"DeploymentId": {
"Ref": "booksapiDeployment308B08F1c828b08824c062376eba921738884f85"
"Ref": "booksapiDeployment308B08F132cc25cf8168bd5e99b9e6d4915866b5"
},
"StageName": "prod"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Name": "my-api"
}
},
"myapiDeployment92F2CB49916eaecf87f818f1e175215b8d086029": {
"myapiDeployment92F2CB4972a890db5063ec679071ba7eefc76f2a": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand All @@ -25,7 +25,7 @@
"Ref": "myapi4C7BF186"
},
"DeploymentId": {
"Ref": "myapiDeployment92F2CB49916eaecf87f818f1e175215b8d086029"
"Ref": "myapiDeployment92F2CB4972a890db5063ec679071ba7eefc76f2a"
},
"StageName": "prod"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Name": "my-api"
}
},
"myapiDeployment92F2CB4919460d935da8177bcfbc418506e514ff": {
"myapiDeployment92F2CB4963d40685c54c6f8da21d80a83f16d3d5": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand Down Expand Up @@ -38,7 +38,7 @@
"CacheClusterEnabled": true,
"CacheClusterSize": "0.5",
"DeploymentId": {
"Ref": "myapiDeployment92F2CB4919460d935da8177bcfbc418506e514ff"
"Ref": "myapiDeployment92F2CB4963d40685c54c6f8da21d80a83f16d3d5"
},
"Description": "beta stage",
"MethodSettings": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"Name": "SecondRestAPI"
}
},
"BooksApiDeployment86CA39AFc929a0f95f673e230c62e2c9754726f6": {
"BooksApiDeployment86CA39AF7e6c771d47a1a3777eba99bffc037822": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand All @@ -96,7 +96,7 @@
"Ref": "BooksApi60AC975F"
},
"DeploymentId": {
"Ref": "BooksApiDeployment86CA39AFc929a0f95f673e230c62e2c9754726f6"
"Ref": "BooksApiDeployment86CA39AF7e6c771d47a1a3777eba99bffc037822"
},
"StageName": "prod"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"Name": "hello-api"
}
},
"helloapiDeploymentFA89AEEC086c88c5044fbc117bd88fffcee53ab2": {
"helloapiDeploymentFA89AEEC3622d8c965f356a33fd95586d24bf138": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand All @@ -76,7 +76,7 @@
"Ref": "helloapi4446A35B"
},
"DeploymentId": {
"Ref": "helloapiDeploymentFA89AEEC086c88c5044fbc117bd88fffcee53ab2"
"Ref": "helloapiDeploymentFA89AEEC3622d8c965f356a33fd95586d24bf138"
},
"StageName": "prod"
}
Expand Down Expand Up @@ -265,7 +265,7 @@
"Name": "second-api"
}
},
"secondapiDeployment20F2C7001932445454ace403a6bfe89c1430ff70": {
"secondapiDeployment20F2C70088fa5a027620045bea3e5043c6d31f5a": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand All @@ -285,7 +285,7 @@
"Ref": "secondapi730EF3C7"
},
"DeploymentId": {
"Ref": "secondapiDeployment20F2C7001932445454ace403a6bfe89c1430ff70"
"Ref": "secondapiDeployment20F2C70088fa5a027620045bea3e5043c6d31f5a"
},
"StageName": "prod"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@
}
}
},
"MyApiDeploymentECB0D05E4316cb89aa1d468052daa78055609f5a": {
"MyApiDeploymentECB0D05E7a475a505b0c925e193030293593b6dc": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
Expand All @@ -650,7 +650,7 @@
"Ref": "MyApi49610EDF"
},
"DeploymentId": {
"Ref": "MyApiDeploymentECB0D05E4316cb89aa1d468052daa78055609f5a"
"Ref": "MyApiDeploymentECB0D05E7a475a505b0c925e193030293593b6dc"
},
"StageName": "prod"
}
Expand Down
23 changes: 13 additions & 10 deletions packages/@aws-cdk/aws-apigateway/test/test.deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export = {
Name: 'api',
},
},
deployment33381975: {
deployment33381975bba46c5132329b81e7befcbbba5a0e75: {
Type: 'AWS::ApiGateway::Deployment',
Properties: {
RestApiId: {
Expand Down Expand Up @@ -97,7 +97,7 @@ export = {
Name: 'api',
},
},
deployment33381975: {
deployment33381975bba46c5132329b81e7befcbbba5a0e75: {
Type: 'AWS::ApiGateway::Deployment',
Properties: {
RestApiId: {
Expand Down Expand Up @@ -133,30 +133,33 @@ export = {
test.done();
},

'"addToLogicalId" will "salt" the logical ID of the deployment resource'(test: Test) {
'logical ID of the deployment resource is salted'(test: Test) {
// GIVEN
const stack = new Stack();
const api = new apigateway.RestApi(stack, 'api', { deploy: false, cloudWatchRole: false });
const deployment = new apigateway.Deployment(stack, 'deployment', { api });
api.root.addMethod('GET');

// default logical ID (with no "salt")
test.ok(synthesize().Resources.deployment33381975);
const resources = synthesize().Resources;
test.ok(resources.deployment33381975bba46c5132329b81e7befcbbba5a0e75,
`resource deployment33381975bba46c5132329b81e7befcbbba5a0e75 not found, instead found ${Object.keys(resources)}`);

// adding some salt
deployment.addToLogicalId({ foo: 123 }); // add some data to the logical ID

// the logical ID changed
const template = synthesize();
test.ok(!template.Resources.deployment33381975, 'old resource id deleted');
test.ok(template.Resources.deployment33381975427670fa9e4148dc851927485bdf36a5, 'new resource is created');
test.ok(!template.Resources.deployment33381975bba46c5132329b81e7befcbbba5a0e75, 'old resource id is not deleted');
test.ok(template.Resources.deployment33381975075f46a4503208d69fcffed2f263c48c,
`new resource deployment33381975075f46a4503208d69fcffed2f263c48c is not created, instead found ${Object.keys(template.Resources)}`);

// tokens supported, and are resolved upon synthesis
const value = 'hello hello';
deployment.addToLogicalId({ foo: Lazy.stringValue({ produce: () => value }) });

const template2 = synthesize();
test.ok(template2.Resources.deployment33381975a12dfe81474913364dc31c06e37f9449);
test.ok(template2.Resources.deployment33381975b6d7672e4c9afd0b741e41d07739786b,
`resource deployment33381975b6d7672e4c9afd0b741e41d07739786b not found, instead found ${Object.keys(template2.Resources)}`);

test.done();

Expand Down Expand Up @@ -214,10 +217,10 @@ export = {

// THEN
expect(stack1).to(haveResource('AWS::ApiGateway::Stage', {
DeploymentId: { Ref: 'myapiDeploymentB7EF8EB7e0b8372768854261d2d1218739e0a307' },
DeploymentId: { Ref: 'myapiDeploymentB7EF8EB74c5295c27fa87ff13f4d04e13f67662d' },
}));
expect(stack2).to(haveResource('AWS::ApiGateway::Stage', {
DeploymentId: { Ref: 'myapiDeploymentB7EF8EB77c517352b0f7ab73c333e36585c8f1f3' },
DeploymentId: { Ref: 'myapiDeploymentB7EF8EB7b50d305057ba109c118e4aafd4509355' },
}));
test.done();
},
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-apigateway/test/test.restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export = {
},
},
},
myapiDeployment92F2CB49916eaecf87f818f1e175215b8d086029: {
myapiDeployment92F2CB4972a890db5063ec679071ba7eefc76f2a: {
Type: 'AWS::ApiGateway::Deployment',
Properties: {
RestApiId: { Ref: 'myapi4C7BF186' },
Expand All @@ -48,7 +48,7 @@ export = {
Type: 'AWS::ApiGateway::Stage',
Properties: {
RestApiId: { Ref: 'myapi4C7BF186' },
DeploymentId: { Ref: 'myapiDeployment92F2CB49916eaecf87f818f1e175215b8d086029' },
DeploymentId: { Ref: 'myapiDeployment92F2CB4972a890db5063ec679071ba7eefc76f2a' },
StageName: 'prod',
},
},
Expand Down Expand Up @@ -590,7 +590,7 @@ export = {
'myapiAccountC3A4750C',
'myapiCloudWatchRoleEB425128',
'myapiGET9B7CD29E',
'myapiDeploymentB7EF8EB75c091a668064a3f3a1f6d68a3fb22cf9',
'myapiDeploymentB7EF8EB7b8edc043bcd33e0d85a3c85151f47e98',
'myapiDeploymentStageprod329F21FF',
'myapi162F20B8',
],
Expand Down
Loading

0 comments on commit 2209bf7

Please sign in to comment.