// 创建桶并且开启对象锁定
s3Client.CreateBucket(&s3.CreateBucketInput{ Bucket: aws.String("bucketname"), ObjectLockEnabledForBucket: aws.Bool(true), }) // 修改桶的默认保留期限 // 调用者需要s3:PutBucketObjectLockConfiguration权限 s3Client.PutObjectLockConfiguration(&s3.PutObjectLockConfigurationInput{ Bucket: aws.String("bucketname"), ObjectLockConfiguration: &s3.ObjectLockConfiguration{ ObjectLockEnabled: aws.String("Enabled"), Rule: &s3.ObjectLockRule{ DefaultRetention: &s3.DefaultRetention{ Mode: aws.String("GOVERNANCE"), Days: aws.Int64(10), }, }, }, }) // 设置对象的保留期限规则 // 调用者需要s3:PutObjectRetention权限 retainUntil := time.Now().Add(30 * 24 * time.Hour) s3Client.PutObjectRetention(&s3.PutObjectRetentionInput{ Bucket: aws.String("bucketname"), Key: aws.String("objectname"), VersionId: aws.String("version"), Retention: &s3.ObjectLockRetention{ Mode: aws.String("GOVERNANCE"), RetainUntilDate: &retainUntil, }, }) // 设置对象的依法保留标记 // 调用者需要s3:PutObjectLegalHold权限 client.PutObjectLegalHoldRequest(&s3.PutObjectLegalHoldInput{ Bucket: aws.String("bucketname"), Key: aws.String("objectname"), VersionId: aws.String("version"), LegalHold: &s3.ObjectLockLegalHold{ Status: aws.String("ON"), }, }) |