Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cloudfront): can't create the default log bucket #25298

Merged
merged 3 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"20.0.0"}
{"version":"31.0.0"}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "20.0.0",
"version": "31.0.0",
"files": {
"9dc2b1d91bf8dc7a564007d2b8c42cfbe1048645014b8bcda1610f778f32d174": {
"d07498b95e3a0a153a16e1cc45cdd588cc73020e9f653aecbaf1cfa16a99f262": {
"source": {
"path": "integ-distribution-extensive.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "9dc2b1d91bf8dc7a564007d2b8c42cfbe1048645014b8bcda1610f778f32d174.json",
"objectKey": "d07498b95e3a0a153a16e1cc45cdd588cc73020e9f653aecbaf1cfa16a99f262.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
}
}
]
},
"OwnershipControls": {
"Rules": [
{
"ObjectOwnership": "ObjectWriter"
}
]
}
},
"UpdateReplacePolicy": "Retain",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "20.0.0",
"version": "31.0.0",
"testCases": {
"integ.distribution-extensive": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"version": "20.0.0",
"version": "31.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
},
"integ-distribution-extensive.assets": {
"type": "cdk:asset-manifest",
"properties": {
Expand All @@ -23,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/9dc2b1d91bf8dc7a564007d2b8c42cfbe1048645014b8bcda1610f778f32d174.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/d07498b95e3a0a153a16e1cc45cdd588cc73020e9f653aecbaf1cfa16a99f262.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -65,6 +59,12 @@
]
},
"displayName": "integ-distribution-extensive"
},
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
"id": "App",
"path": "",
"children": {
"Tree": {
"id": "Tree",
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.85"
}
},
"integ-distribution-extensive": {
"id": "integ-distribution-extensive",
"path": "integ-distribution-extensive",
Expand All @@ -25,7 +17,7 @@
"path": "integ-distribution-extensive/MyDist/Origin1",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.85"
"version": "10.1.270"
}
},
"LoggingBucket": {
Expand All @@ -46,18 +38,25 @@
}
}
]
},
"ownershipControls": {
"rules": [
{
"objectOwnership": "ObjectWriter"
}
]
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-s3.CfnBucket",
"version": "0.0.0"
"fqn": "constructs.Construct",
"version": "10.1.270"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-s3.Bucket",
"version": "0.0.0"
"fqn": "constructs.Construct",
"version": "10.1.270"
}
},
"Resource": {
Expand Down Expand Up @@ -116,26 +115,50 @@
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-cloudfront.CfnDistribution",
"version": "0.0.0"
"fqn": "constructs.Construct",
"version": "10.1.270"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-cloudfront.Distribution",
"version": "0.0.0"
"fqn": "constructs.Construct",
"version": "10.1.270"
}
},
"BootstrapVersion": {
"id": "BootstrapVersion",
"path": "integ-distribution-extensive/BootstrapVersion",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.270"
}
},
"CheckBootstrapVersion": {
"id": "CheckBootstrapVersion",
"path": "integ-distribution-extensive/CheckBootstrapVersion",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.270"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.85"
"version": "10.1.270"
}
},
"Tree": {
"id": "Tree",
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.270"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.85"
"version": "10.1.270"
}
}
}
4 changes: 3 additions & 1 deletion packages/aws-cdk-lib/aws-cloudfront/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,9 @@ new cloudfront.Distribution(this, 'myDist', {
new cloudfront.Distribution(this, 'myDist', {
defaultBehavior: { origin: new origins.HttpOrigin('www.example.com') },
enableLogging: true, // Optional, this is implied if logBucket is specified
logBucket: new s3.Bucket(this, 'LogBucket'),
logBucket: new s3.Bucket(this, 'LogBucket', {
objectOwnership: s3.ObjectOwnership.OBJECT_WRITER,
}),
logFilePrefix: 'distribution-access-logs/',
logIncludesCookies: true,
});
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export interface DistributionProps {

/**
* The Amazon S3 bucket to store the access logs in.
* Make sure to set `objectOwnership` to `s3.ObjectOwnership.OBJECT_WRITER` in your custom bucket.
*
* @default - A bucket is created if `enableLogging` is true
*/
Expand Down Expand Up @@ -498,6 +499,8 @@ export class Distribution extends Resource implements IDistribution {

const bucket = props.logBucket ?? new s3.Bucket(this, 'LoggingBucket', {
encryption: s3.BucketEncryption.S3_MANAGED,
// We need set objectOwnership to OBJECT_WRITER to enable ACL, which is disabled by default.
objectOwnership: s3.ObjectOwnership.OBJECT_WRITER,
});
return {
bucket: bucket.bucketRegionalDomainName,
Expand Down
7 changes: 7 additions & 0 deletions packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,13 @@ describe('logging', () => {
},
},
});
Template.fromStack(stack).hasResourceProperties('AWS::S3::Bucket', {
OwnershipControls: {
Rules: [
{ ObjectOwnership: 'ObjectWriter' },
],
},
});
});

test('uses existing bucket if provided', () => {
Expand Down