How to delete or purge old files on S3?

前端 未结 5 1787
盖世英雄少女心
盖世英雄少女心 2020-12-24 10:21

Are there existing solutions to delete any files older than x days?

5条回答
  •  庸人自扰
    2020-12-24 10:57

    Here is how to implement it using a CloudFormation template:

      JenkinsArtifactsBucket:
        Type: "AWS::S3::Bucket"
        Properties:
          BucketName: !Sub "jenkins-artifacts"
          LifecycleConfiguration:
            Rules:
              - Id: "remove-old-artifacts"
                ExpirationInDays: 3
                NoncurrentVersionExpirationInDays: 3
                Status: Enabled
    

    This creates a lifecycle rule as explained by @Ravi Bhatt

    Read more on that: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-lifecycleconfig-rule.html

    How object lifecycle management works: https://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html

提交回复
热议问题