I want to empty a bucket using the AWS SDK for JavaScript. According to the documentation, "If you want the S3 Lifecycle rule to apply to all objects in the bucket, specify an empty prefix". However, I'm not sure how to do this. When I don't include a "Prefix" or a "Filter" property or include a "Filter" with an undefined "Prefix", I receive an error response of "MalformedXML: The XML you provided was not well-formed or did not validate against our published schema". The rule I'm trying to send is shown below:
const params = {
Bucket: "bucket-name",
LifecycleConfiguration: {
Rules: {
ID: "Empty bucket s3",
Filter: {
}
Status: "Enabled",
Expiration: {
Days: 1
},
AbortIncompleteMultipartUpload: {
DaysAfterInitiation: 1
}
}
};
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
This is not possible using boto3, the example:
lifecycle_configuration = {
'Rules': [
{
'Expiration': {
'Days': 1,
},
'ID': 'DeleteAfter1Days',
'Status': 'Enabled',
'Prefix': '',
'NoncurrentVersionExpiration': {
'NoncurrentDays': 1
},
'AbortIncompleteMultipartUpload': {
'DaysAfterInitiation': 1
}
},
{
'Expiration': {
'ExpiredObjectDeleteMarker': True
},
'ID': 'ExpireDeleteMarkers',
'Status': 'Enabled',
'Prefix': '*'
}
]
}
print(f'Creating lifecyle for {bucket_name}')
s3.put_bucket_lifecycle_configuration(
Bucket=bucket_name,
LifecycleConfiguration=lifecycle_configuration
)
will result in "An error occurred (InvalidRequest) when calling the PutBucketLifecycleConfiguration operation: Found overlapping prefixes '*' and '' for same action type 'Expiration'"
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
I did this for my bucket, but it's been 2 days now and there is still data in my bucket? Does the rule not run automatically everyday?
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
In the past, if you had a large number of objects in a bucket, you could get a very large bill for LIST API calls before the DELETE calls. Can you verify that if the Lifecycle Policy above is used that you will not get a large bill for deleting millions/billions of objects?
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
Did we find any solution to make it work in boto3?
Relevant content
- asked 7 months ago
- asked a year ago
- Accepted Answerasked 2 years ago
- asked 3 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 4 years ago