diff --git a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts index c8fe45efbb611..987737c4dca96 100644 --- a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts +++ b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts @@ -760,7 +760,7 @@ export class CloudFrontWebDistribution extends cdk.Construct implements IDistrib const {acmCertRef, securityPolicy, sslMethod, names: aliases} = props.aliasConfiguration; _viewerCertificate = ViewerCertificate.fromAcmCertificate( - certificatemanager.Certificate.fromCertificateArn(scope, 'AliasConfigurationCert', acmCertRef), + certificatemanager.Certificate.fromCertificateArn(this, 'AliasConfigurationCert', acmCertRef), { securityPolicy, sslMethod, aliases } ); } diff --git a/packages/@aws-cdk/aws-cloudfront/test/test.basic.ts b/packages/@aws-cdk/aws-cloudfront/test/test.basic.ts index 107e954553213..083e874948735 100644 --- a/packages/@aws-cdk/aws-cloudfront/test/test.basic.ts +++ b/packages/@aws-cdk/aws-cloudfront/test/test.basic.ts @@ -479,6 +479,46 @@ export = { test.done(); }, + 'allows multiple aliasConfiguration CloudFrontWebDistribution per stack'(test: Test) { + const stack = new cdk.Stack(); + const s3BucketSource = new s3.Bucket(stack, 'Bucket'); + + const originConfigs = [{ + s3OriginSource: {s3BucketSource}, + behaviors: [{ isDefaultBehavior: true }] + }]; + + new CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably', { + originConfigs, + aliasConfiguration: {acmCertRef: 'acm_ref', names: ['www.example.com']}, + }); + new CloudFrontWebDistribution(stack, 'AnotherAmazingWebsiteProbably', { + originConfigs, + aliasConfiguration: {acmCertRef: 'another_acm_ref', names: ['ftp.example.com']}, + }); + + expect(stack).to(haveResourceLike('AWS::CloudFront::Distribution', { + "DistributionConfig": { + "Aliases": ["www.example.com"], + "ViewerCertificate": { + "AcmCertificateArn": "acm_ref", + "SslSupportMethod": "sni-only" + } + } + })); + + expect(stack).to(haveResourceLike('AWS::CloudFront::Distribution', { + "DistributionConfig": { + "Aliases": ["ftp.example.com"], + "ViewerCertificate": { + "AcmCertificateArn": "another_acm_ref", + "SslSupportMethod": "sni-only" + } + } + })); + test.done(); + }, + 'viewerCertificate': { 'acmCertificate': { 'base usage'(test: Test) {