diff --git a/packages/@aws-cdk/aws-cloudfront-origins/lib/s3-origin.ts b/packages/@aws-cdk/aws-cloudfront-origins/lib/s3-origin.ts index b976e482b2276..3e6a2e9e19c87 100644 --- a/packages/@aws-cdk/aws-cloudfront-origins/lib/s3-origin.ts +++ b/packages/@aws-cdk/aws-cloudfront-origins/lib/s3-origin.ts @@ -26,39 +26,22 @@ export interface S3OriginProps { * * @experimental */ -export class S3Origin extends cloudfront.Origin { - - private readonly origin: cloudfront.Origin; +export class S3Origin implements cloudfront.IOrigin { + private readonly origin: cloudfront.IOrigin; constructor(bucket: s3.IBucket, props: S3OriginProps = {}) { - let proxyOrigin; - if (bucket.isWebsite) { - proxyOrigin = new cloudfront.HttpOrigin(bucket.bucketWebsiteDomainName, { + this.origin = bucket.isWebsite + ? new cloudfront.HttpOrigin(bucket.bucketWebsiteDomainName, { protocolPolicy: cloudfront.OriginProtocolPolicy.HTTP_ONLY, // S3 only supports HTTP for website buckets ...props, - }); - } else { - proxyOrigin = new cloudfront.S3Origin({ + }) + : new cloudfront.S3Origin({ bucket, ...props, }); - } - - super(proxyOrigin.domainName); - - this.origin = proxyOrigin; } - public get id() { - return this.origin.id; + public bind(scope: cdk.Construct, options: cloudfront.OriginBindOptions): cloudfront.OriginBindConfig { + return this.origin.bind(scope, options); } - - public bind(scope: cdk.Construct, options: cloudfront.OriginBindOptions) { - this.origin.bind(scope, options); - } - - public renderOrigin() { - return this.origin.renderOrigin(); - } - } diff --git a/packages/@aws-cdk/aws-cloudfront-origins/test/http-origin.test.ts b/packages/@aws-cdk/aws-cloudfront-origins/test/http-origin.test.ts index a5475dc4c760b..246392355586e 100644 --- a/packages/@aws-cdk/aws-cloudfront-origins/test/http-origin.test.ts +++ b/packages/@aws-cdk/aws-cloudfront-origins/test/http-origin.test.ts @@ -15,9 +15,9 @@ beforeEach(() => { test('Renders minimal example with just a domain name', () => { const origin = new HttpOrigin('www.example.com'); - origin.bind(stack, { originIndex: 0 }); + const originBindConfig = origin.bind(stack, { originId: 'StackOrigin029E19582' }); - expect(origin.renderOrigin()).toEqual({ + expect(originBindConfig.originProperty).toEqual({ id: 'StackOrigin029E19582', domainName: 'www.example.com', customOriginConfig: { @@ -32,9 +32,9 @@ test('Can customize properties of the origin', () => { readTimeout: Duration.seconds(10), protocolPolicy: cloudfront.OriginProtocolPolicy.MATCH_VIEWER, }); - origin.bind(stack, { originIndex: 0 }); + const originBindConfig = origin.bind(stack, { originId: 'StackOrigin029E19582' }); - expect(origin.renderOrigin()).toEqual({ + expect(originBindConfig.originProperty).toEqual({ id: 'StackOrigin029E19582', domainName: 'www.example.com', originCustomHeaders: [{ diff --git a/packages/@aws-cdk/aws-cloudfront-origins/test/integ.s3-origin.expected.json b/packages/@aws-cdk/aws-cloudfront-origins/test/integ.s3-origin.expected.json index 64455613ffcbc..173044c7a0dab 100644 --- a/packages/@aws-cdk/aws-cloudfront-origins/test/integ.s3-origin.expected.json +++ b/packages/@aws-cdk/aws-cloudfront-origins/test/integ.s3-origin.expected.json @@ -23,7 +23,7 @@ "Principal": { "CanonicalUser": { "Fn::GetAtt": [ - "DistributionS3Origin115FD918D", + "DistributionOrigin1S3Origin5F5C0696", "S3CanonicalUserId" ] } @@ -56,7 +56,7 @@ } } }, - "DistributionS3Origin115FD918D": { + "DistributionOrigin1S3Origin5F5C0696": { "Type": "AWS::CloudFront::CloudFrontOriginAccessIdentity", "Properties": { "CloudFrontOriginAccessIdentityConfig": { @@ -92,7 +92,7 @@ [ "origin-access-identity/cloudfront/", { - "Ref": "DistributionS3Origin115FD918D" + "Ref": "DistributionOrigin1S3Origin5F5C0696" } ] ] @@ -104,4 +104,4 @@ } } } -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/aws-cloudfront-origins/test/load-balancer-origin.test.ts b/packages/@aws-cdk/aws-cloudfront-origins/test/load-balancer-origin.test.ts index c06c9cc7a7b84..e4ad46372fbef 100644 --- a/packages/@aws-cdk/aws-cloudfront-origins/test/load-balancer-origin.test.ts +++ b/packages/@aws-cdk/aws-cloudfront-origins/test/load-balancer-origin.test.ts @@ -21,9 +21,9 @@ test('Renders minimal example with just a load balancer', () => { }); const origin = new LoadBalancerV2Origin(loadBalancer); - origin.bind(stack, { originIndex: 0 }); + const originBindConfig = origin.bind(stack, { originId: 'StackOrigin029E19582' }); - expect(origin.renderOrigin()).toEqual({ + expect(originBindConfig.originProperty).toEqual({ id: 'StackOrigin029E19582', domainName: loadBalancer.loadBalancerDnsName, customOriginConfig: { @@ -43,9 +43,9 @@ test('Can customize properties of the origin', () => { connectionTimeout: Duration.seconds(5), protocolPolicy: cloudfront.OriginProtocolPolicy.MATCH_VIEWER, }); - origin.bind(stack, { originIndex: 0 }); + const originBindConfig = origin.bind(stack, { originId: 'StackOrigin029E19582' }); - expect(origin.renderOrigin()).toEqual({ + expect(originBindConfig.originProperty).toEqual({ id: 'StackOrigin029E19582', domainName: loadBalancer.loadBalancerDnsName, connectionAttempts: 3, diff --git a/packages/@aws-cdk/aws-cloudfront-origins/test/s3-origin.test.ts b/packages/@aws-cdk/aws-cloudfront-origins/test/s3-origin.test.ts index c851f53b122a0..9c0380411e494 100644 --- a/packages/@aws-cdk/aws-cloudfront-origins/test/s3-origin.test.ts +++ b/packages/@aws-cdk/aws-cloudfront-origins/test/s3-origin.test.ts @@ -17,9 +17,9 @@ test('With non-website bucket, renders all required properties, including S3Orig const bucket = new s3.Bucket(stack, 'Bucket'); const origin = new S3Origin(bucket); - origin.bind(stack, { originIndex: 0 }); + const originBindConfig = origin.bind(stack, { originId: 'StackOrigin029E19582' }); - expect(origin.renderOrigin()).toEqual({ + expect(originBindConfig.originProperty).toEqual({ id: 'StackOrigin029E19582', domainName: bucket.bucketRegionalDomainName, s3OriginConfig: { @@ -34,9 +34,9 @@ test('With website bucket, renders all required properties, including custom ori }); const origin = new S3Origin(bucket); - origin.bind(stack, { originIndex: 0 }); + const originBindConfig = origin.bind(stack, { originId: 'StackOrigin029E19582' }); - expect(origin.renderOrigin()).toEqual({ + expect(originBindConfig.originProperty).toEqual({ id: 'StackOrigin029E19582', domainName: bucket.bucketWebsiteDomainName, customOriginConfig: { @@ -51,9 +51,9 @@ test('Respects props passed down to underlying origin', () => { }); const origin = new S3Origin(bucket, { originPath: '/website' }); - origin.bind(stack, { originIndex: 0 }); + const originBindConfig = origin.bind(stack, { originId: 'StackOrigin029E19582' }); - expect(origin.renderOrigin()).toEqual({ + expect(originBindConfig.originProperty).toEqual({ id: 'StackOrigin029E19582', domainName: bucket.bucketWebsiteDomainName, originPath: '/website', @@ -61,4 +61,4 @@ test('Respects props passed down to underlying origin', () => { originProtocolPolicy: 'http-only', }, }); -}); \ No newline at end of file +});