Skip to content

Commit

Permalink
fix(cloudfront): Escape hatch support for Distribution
Browse files Browse the repository at this point in the history
Changed the ID for the CfnDistribution to support escape hatches
(`dist.node.defaultChild`).

fixes #9620

BREAKING CHANGE: (cloudfront) Changed IDs for Distributions
  • Loading branch information
njlynch committed Aug 12, 2020
1 parent a772fe8 commit dff6799
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Resources": {
"DistributionCFDistribution882A7313": {
"Distribution830FAC52": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
}
}
},
"DistributionCFDistribution882A7313": {
"Distribution830FAC52": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
Expand Down Expand Up @@ -430,4 +430,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
}
}
},
"DistributionCFDistribution882A7313": {
"Distribution830FAC52": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
Expand Down Expand Up @@ -141,4 +141,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
}
}
},
"DistributionCFDistribution882A7313": {
"Distribution830FAC52": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront/lib/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class Distribution extends Resource implements IDistribution {
this.certificate = props.certificate;
this.errorResponses = props.errorResponses ?? [];

const distribution = new CfnDistribution(this, 'CFDistribution', { distributionConfig: {
const distribution = new CfnDistribution(this, 'Resource', { distributionConfig: {
enabled: true,
origins: Lazy.anyValue({ produce: () => this.renderOrigins() }),
originGroups: Lazy.anyValue({ produce: () => this.renderOriginGroups() }),
Expand Down
18 changes: 18 additions & 0 deletions packages/@aws-cdk/aws-cloudfront/test/distribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,24 @@ test('price class is included if provided', () => {
});
});

test('escape hatches are supported', () => {
const dist = new Distribution(stack, 'Dist', {
defaultBehavior: { origin: defaultOrigin },
});
const cfnDist = dist.node.defaultChild as CfnDistribution;
cfnDist.addPropertyOverride('DistributionConfig.DefaultCacheBehavior.ForwardedValues.Headers', ['*']);

expect(stack).toHaveResourceLike('AWS::CloudFront::Distribution', {
DistributionConfig: {
DefaultCacheBehavior: {
ForwardedValues: {
Headers: ['*'],
},
},
},
});
});

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

0 comments on commit dff6799

Please sign in to comment.