aws cli s3api put-bucket-lifecycle error multi staged transition

0

I'm using aws s3api put-bucket-lifecycle --bucket bkp --lifecycle-configuration file://move-to-glacier.json --debug, for create lifecycle rule in many buckets, this is my move-to-glacier.json:

{
    "Rules": [
        {
            "ID": "MoveToGlacier",
            "Prefix": "",
            "Status": "Enabled",
            "Transition": [
                {
                    "Days": 365,
                    "StorageClass": "GLACIER"
                },
                {
                    "Days": 1825,
                    "StorageClass": "DEEP_ARCHIVE"
                }
            ]
        }
    ]
}

First 365 day move to GLACIER, Second 1825 move to DEEP_ARCHIVE, all bucket, but return error:

  File "botocore/client.py", line 617, in _convert_to_request_dict
  File "botocore/validate.py", line 319, in serialize_to_request
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter LifecycleConfiguration.Rules[0].Transition, value: [OrderedDict([('Days', 365), ('StorageClass', 'GLACIER')]), OrderedDict([('Days', 1825), ('StorageClass', 'DEEP_ARCHIVE')])], type: <class 'list'>, valid types: <class 'dict'>

If i using my move-to-glacier.json with one transition it run ok, example:

{
    "Rules": [
        {
            "ID": "MoveToGlacier",
            "Prefix": "",
            "Status": "Enabled",
            "Transition": 
                {
                    "Days": 365,
                    "StorageClass": "GLACIER"
                }
            
        }
    ]
}

With this move-to-glacier the command s3api put-bucket-lifecycle run ok.

profile picture
asked a year ago282 views
3 Answers
0
Accepted Answer

I changed my mind, I'm using boto3 SDK and it worked correctly.

import boto3
s3 = boto3.resource('s3')
bucket_lifecycle_configuration = s3.BucketLifecycleConfiguration('my-bucket')
response = bucket_lifecycle_configuration.put(
    LifecycleConfiguration={
        'Rules': [
            {
                'ID': 'Move-To-Glacier',
                'Prefix': '',
                'Status': 'Enabled',
                'Transitions': [
                    {
                        'Days': 365,
                        'StorageClass': 'GLACIER'
                    },
                    {
                        'Days': 1825,
                        'StorageClass': 'DEEP_ARCHIVE'
                    }
                ],
            }
        ]
    }
)
print(response)
profile picture
answered a year ago
0

There is typo in your "Transitions" keyword. Refer the documentation here

So the correct format will be

{
    "Rules": [
        {
            "ID": "MoveToGlacier",
            "Prefix": "",
            "Status": "Enabled",
            "Transitions": [
                {
                    "Days": 365,
                    "StorageClass": "GLACIER"
                },
                {
                    "Days": 1825,
                    "StorageClass": "DEEP_ARCHIVE"
                }
            ]
        }
    ]
}
AWS
EXPERT
Gokul
answered a year ago
  • Parameter validation failed: Unknown parameter in LifecycleConfiguration.Rules[0]: "Transitions", must be one of: Expiration, ID, Prefix, Status, Transition, NoncurrentVersionTransition, NoncurrentVersionExpiration, AbortIncompleteMultipartUpload.

    The param is correct "Transition". This message i get by logs

0

Make sure you have an updated version of the CLI. Sometimes having an older version that does not know about "DEEP_ARCHIVE" will produce this type of error.

profile pictureAWS
EXPERT
kentrad
answered a year ago
  • i'm latest version:

    aws --version aws-cli/2.9.23 Python/3.9.11 Linux/5.4.72-microsoft-standard-WSL2 exe/x86_64.ubuntu.20 prompt/off

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions