Skip to content

Commit

Permalink
Merge branch 'master' into lambda-nodejs-esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
jogold committed Nov 17, 2020
2 parents 5623bd5 + 90f0b9d commit ad3a010
Show file tree
Hide file tree
Showing 22 changed files with 257 additions and 101 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront-origins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
"aws-sdk": "^2.793.0",
"aws-sdk": "^2.794.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"pkglint": "0.0.0"
Expand Down
6 changes: 4 additions & 2 deletions packages/@aws-cdk/aws-cloudfront/lib/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,15 @@ export class Distribution extends Resource implements IDistribution {
}

private addOrigin(origin: IOrigin, isFailoverOrigin: boolean = false): string {
const ORIGIN_ID_MAX_LENGTH = 128;

const existingOrigin = this.boundOrigins.find(boundOrigin => boundOrigin.origin === origin);
if (existingOrigin) {
return existingOrigin.originGroupId ?? existingOrigin.originId;
} else {
const originIndex = this.boundOrigins.length + 1;
const scope = new CoreConstruct(this, `Origin${originIndex}`);
const originId = Names.uniqueId(scope);
const originId = Names.uniqueId(scope).slice(-ORIGIN_ID_MAX_LENGTH);
const originBindConfig = origin.bind(scope, { originId });
if (!originBindConfig.failoverConfig) {
this.boundOrigins.push({ origin, originId, ...originBindConfig });
Expand All @@ -331,7 +333,7 @@ export class Distribution extends Resource implements IDistribution {
throw new Error('An Origin cannot use an Origin with its own failover configuration as its fallback origin!');
}
const groupIndex = this.originGroups.length + 1;
const originGroupId = Names.uniqueId(new CoreConstruct(this, `OriginGroup${groupIndex}`));
const originGroupId = Names.uniqueId(new CoreConstruct(this, `OriginGroup${groupIndex}`)).slice(-ORIGIN_ID_MAX_LENGTH);
this.boundOrigins.push({ origin, originId, originGroupId, ...originBindConfig });

const failoverOriginId = this.addOrigin(originBindConfig.failoverConfig.failoverOrigin, true);
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"aws-sdk": "^2.793.0",
"aws-sdk": "^2.794.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
40 changes: 38 additions & 2 deletions packages/@aws-cdk/aws-cloudfront/test/distribution.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ABSENT } from '@aws-cdk/assert';
import { ABSENT, objectLike } from '@aws-cdk/assert';
import '@aws-cdk/assert/jest';
import * as acm from '@aws-cdk/aws-certificatemanager';
import * as lambda from '@aws-cdk/aws-lambda';
import * as s3 from '@aws-cdk/aws-s3';
import { App, Duration, Stack } from '@aws-cdk/core';
import { CfnDistribution, Distribution, GeoRestriction, HttpVersion, IOrigin, LambdaEdgeEventType, PriceClass } from '../lib';
import { defaultOrigin } from './test-origin';
import { defaultOrigin, defaultOriginGroup } from './test-origin';

let app: App;
let stack: Stack;
Expand Down Expand Up @@ -708,3 +708,39 @@ test('escape hatches are supported', () => {
},
});
});

describe('origin IDs', () => {
test('origin ID is limited to 128 characters', () => {
const nestedStack = new Stack(stack, 'LongNameThatWillEndUpGeneratingAUniqueNodeIdThatIsLongerThanTheOneHundredAndTwentyEightCharacterLimit');

new Distribution(nestedStack, 'AReallyAwesomeDistributionWithAMemorableNameThatIWillNeverForget', {
defaultBehavior: { origin: defaultOrigin() },
});

expect(nestedStack).toHaveResourceLike('AWS::CloudFront::Distribution', {
DistributionConfig: {
Origins: [objectLike({
Id: 'ngerThanTheOneHundredAndTwentyEightCharacterLimitAReallyAwesomeDistributionWithAMemorableNameThatIWillNeverForgetOrigin1D38031F9',
})],
},
});
});

test('origin group ID is limited to 128 characters', () => {
const nestedStack = new Stack(stack, 'LongNameThatWillEndUpGeneratingAUniqueNodeIdThatIsLongerThanTheOneHundredAndTwentyEightCharacterLimit');

new Distribution(nestedStack, 'AReallyAwesomeDistributionWithAMemorableNameThatIWillNeverForget', {
defaultBehavior: { origin: defaultOriginGroup() },
});

expect(nestedStack).toHaveResourceLike('AWS::CloudFront::Distribution', {
DistributionConfig: {
OriginGroups: {
Items: [objectLike({
Id: 'hanTheOneHundredAndTwentyEightCharacterLimitAReallyAwesomeDistributionWithAMemorableNameThatIWillNeverForgetOriginGroup1B5CE3FE6',
})],
},
},
});
});
});
27 changes: 26 additions & 1 deletion packages/@aws-cdk/aws-cloudfront/test/test-origin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { CfnDistribution, IOrigin, OriginBase, OriginProps, OriginProtocolPolicy } from '../lib';
import { CfnDistribution, IOrigin, OriginBase, OriginBindConfig, OriginBindOptions, OriginProps, OriginProtocolPolicy } from '../lib';

// v2 - keep this import as a separate section to reduce merge conflict when forward merging with the v2 branch.
// eslint-disable-next-line
import { Construct } from '@aws-cdk/core';

/** Used for testing common Origin functionality */
export class TestOrigin extends OriginBase {
Expand All @@ -8,6 +12,27 @@ export class TestOrigin extends OriginBase {
}
}

export class TestOriginGroup implements IOrigin {
constructor(private readonly primaryDomainName: string, private readonly secondaryDomainName: string) { }
/* eslint-disable cdk/no-core-construct */
public bind(scope: Construct, options: OriginBindOptions): OriginBindConfig {
const primaryOrigin = new TestOrigin(this.primaryDomainName);
const secondaryOrigin = new TestOrigin(this.secondaryDomainName);

const primaryOriginConfig = primaryOrigin.bind(scope, options);
return {
originProperty: primaryOriginConfig.originProperty,
failoverConfig: {
failoverOrigin: secondaryOrigin,
},
};
}
}

export function defaultOrigin(domainName?: string): IOrigin {
return new TestOrigin(domainName ?? 'www.example.com');
}

export function defaultOriginGroup(): IOrigin {
return new TestOriginGroup('www.example.com', 'foo.example.com');
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudtrail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"aws-sdk": "^2.793.0",
"aws-sdk": "^2.794.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codebuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@aws-cdk/aws-sns": "0.0.0",
"@aws-cdk/aws-sqs": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.793.0",
"aws-sdk": "^2.794.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codecommit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-sns": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.793.0",
"aws-sdk": "^2.794.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-dynamodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/jest": "^26.0.15",
"aws-sdk": "^2.793.0",
"aws-sdk": "^2.794.0",
"aws-sdk-mock": "^5.1.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-eks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.31",
"@types/yaml": "1.9.6",
"aws-sdk": "^2.793.0",
"aws-sdk": "^2.794.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-events-targets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-codecommit": "0.0.0",
"@aws-cdk/aws-s3": "0.0.0",
"aws-sdk": "^2.793.0",
"aws-sdk": "^2.794.0",
"aws-sdk-mock": "^5.1.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.793.0",
"aws-sdk": "^2.794.0",
"aws-sdk-mock": "^5.1.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-route53/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.793.0",
"aws-sdk": "^2.794.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-sqs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-s3": "0.0.0",
"@types/nodeunit": "^0.0.31",
"aws-sdk": "^2.793.0",
"aws-sdk": "^2.794.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
Loading

0 comments on commit ad3a010

Please sign in to comment.