I’m trying to set the lifecycle configuration of a subdirectory in Amazon S3 bucket by using boto3
put_bucket_lifecycle_configuration
. I used this code from aws documentation as referece:
JavaScript
x
11
11
1
lifecycle_config_settings = {
2
'Rules': [
3
{'ID': 'S3 Glacier Transition Rule',
4
'Filter': {'Prefix': ''},
5
'Status': 'Enabled',
6
'Transitions': [
7
{'Days': 0,
8
'StorageClass': 'GLACIER'}
9
]}
10
]}
11
I removed Transitions
and added Expiration
, to better fit my purpouses. Here is my code:
JavaScript
1
21
21
1
myDirectory = 'table-data/'
2
3
lifecycle_config_settings = {
4
'Rules': [{
5
'ID': 'My rule',
6
'Expiration': {
7
'Days': 30,
8
'ExpiredObjectDeleteMarker': True
9
},
10
'Filter': {'Prefix': myDirectory},
11
'Status': 'Enabled'
12
}
13
]}
14
15
s3 = boto3.client('s3')
16
s3.put_bucket_lifecycle_configuration(
17
Bucket=myBucket,
18
LifecycleConfiguration=lifecycle_config_settings
19
)
20
21
The error I’m receiving is:
JavaScript
1
2
1
An error occurred (MalformedXML) when calling the PutBucketLifecycleConfiguration operation: The XML you provided was not well-formed or did not validate against our published schema
2
What could be causing this error?
Advertisement
Answer
I followed @Michael-sqlbot suggestion and found the reason it wasn’t working.
The problem in this settings is in 'ExpiredObjectDeleteMarker': True
that is inside Expiration key
. In boto3 documentation there is an observation about it.
'ExpiredObjectDeleteMarker'
cannot be specified with Days or Date in a Lifecycle Expiration Policy.
Fixing it, the settings will be:
JavaScript
1
11
11
1
lifecycle_config_settings = {
2
'Rules': [{
3
'ID': 'My rule',
4
'Expiration': {
5
'Days': 30
6
},
7
'Filter': {'Prefix': myDirectory},
8
'Status': 'Enabled'
9
}
10
]}
11