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

(s3): remove warnings about Object Lock on existing buckets #29168

Open
blimmer opened this issue Feb 19, 2024 · 3 comments
Open

(s3): remove warnings about Object Lock on existing buckets #29168

blimmer opened this issue Feb 19, 2024 · 3 comments
Labels
@aws-cdk/aws-s3 Related to Amazon S3 documentation This is a problem with documentation. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2

Comments

@blimmer
Copy link
Contributor

blimmer commented Feb 19, 2024

Describe the issue

There are a lot of warnings in the CDK documentation about enabling Object Lock on existing buckets.

It's in the README

[Object Lock](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock-overview.html)
can be configured to enable a write-once-read-many model for an S3 bucket. Object Lock must be
configured when a bucket is created; if a bucket is created without Object Lock, it cannot be
enabled later via the CDK.

And in the in-code comments

/**
* Enable object lock on the bucket.
*
* Enabling object lock for existing buckets is not supported. Object lock must be
* enabled when the bucket is created.
*
* @see https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock-overview.html#object-lock-bucket-config-enable
*
* @default false, unless objectLockDefaultRetention is set (then, true)
*/
readonly objectLockEnabled?: boolean;
/**
* The default retention mode and rules for S3 Object Lock.
*
* Default retention can be configured after a bucket is created if the bucket already
* has object lock enabled. Enabling object lock for existing buckets is not supported.
*
* @see https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock-overview.html#object-lock-bucket-config-enable
*
* @default no default retention period
*/
readonly objectLockDefaultRetention?: ObjectLockRetention;

Links

It looks like, as of Nov 20, 2023, you can now enable this on existing buckets: https://aws.amazon.com/about-aws/whats-new/2023/11/amazon-s3-enabling-object-lock-buckets/

@blimmer blimmer added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels Feb 19, 2024
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Feb 19, 2024
@tim-finnigan tim-finnigan self-assigned this Feb 19, 2024
@tim-finnigan tim-finnigan added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Feb 19, 2024
@tim-finnigan
Copy link

I tried adding Object Lock on an existing bucket using CDK:

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { Bucket } from 'aws-cdk-lib/aws-s3';

export class CdkS3TestStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    
    const bucket = new Bucket(this, 'MyBucket', {
      objectLockEnabled: false,
    });
  }
}

When I changed objectLockEnabled to true and ran cdk diff it shows:

Resources
[~] AWS::S3::Bucket MyBucket MyBucketF68F3111 replace
 └─ [~] ObjectLockEnabled (requires replacement)

Which is a limitation on the underlying CloudFormation resource:

image

So although S3 now supports enabling S3 Object Lock on existing buckets per that recent announcement, I'm not sure that makes this documentation inaccurate, since a new bucket gets created on cdk deploy:

...if a bucket is created without Object Lock, it cannot be enabled later via the CDK.

But I think the "Enabling object lock for existing buckets is not supported." should be changed, because you could make the update via the console or an SDK like the Python SDK (Boto3):

import boto3

s3 = boto3.client('s3')

# Enable versioning on the bucket
# (Required for S3 Object Lock)
s3.put_bucket_versioning(
    Bucket='MyBucket',
    VersioningConfiguration={
        'Status': 'Enabled'
    }
)

# Enable S3 Object Lock
s3.put_object_lock_configuration(
    Bucket='MyBucket',
    ObjectLockConfiguration={
        'ObjectLockEnabled': 'Enabled'
    }
)

@tim-finnigan tim-finnigan added p2 and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Feb 19, 2024
@tim-finnigan tim-finnigan removed their assignment Feb 19, 2024
@blimmer
Copy link
Contributor Author

blimmer commented Feb 20, 2024

Thanks for testing this out for me. Admittedly, I didn't actually try it myself! I filed aws-cloudformation/cloudformation-coverage-roadmap#1929 because CloudFormation should be updated to support this.

I don't love suggesting that people mutate the bucket state outside of CDK, personally. In general, the infrastructure as code should always match the real state of the infrastructure (although, CloudFormation is terrible at that 😓).

Because of that, I'd personally be in favor of waiting on CFN support rather than suggesting that people update it themselves outside of infrastructure as code or providing a Custom Resource.

@tim-finnigan tim-finnigan added feature-request A feature should be added or improved. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. effort/medium Medium work item – several days of effort labels Mar 14, 2024
@blimmer
Copy link
Contributor Author

blimmer commented Mar 20, 2024

Sounds like they're working on this upstream: aws-cloudformation/cloudformation-coverage-roadmap#1929 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 documentation This is a problem with documentation. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2
Projects
None yet
Development

No branches or pull requests

2 participants