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.

3 Antworten
0
Akzeptierte Antwort

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
beantwortet vor einem Jahr
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
EXPERTE
Gokul
beantwortet vor einem Jahr
  • 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
EXPERTE
kentrad
beantwortet vor einem Jahr
  • 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

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen