0
votes

Getting following error for put-bucket-lifecycle-configuration :

[root@ADM-PROD-OMNI noc-scripts]# aws s3api put-bucket-lifecycle-configuration --bucket noc-try --lifecycle-configuration  lifecycle.json
usage: aws [options] <command> <subcommand> [parameters]
aws: error: argument operation: Invalid choice, valid choices are:

abort-multipart-upload                   | complete-multipart-upload
copy-object                              | create-bucket
create-multipart-upload                  | delete-bucket
delete-bucket-cors                       | delete-bucket-lifecycle
delete-bucket-policy                     | delete-bucket-replication
delete-bucket-tagging                    | delete-bucket-website
delete-object                            | delete-objects
get-bucket-acl                           | get-bucket-cors
get-bucket-lifecycle                     | get-bucket-location
get-bucket-logging                       | get-bucket-notification
get-bucket-notification-configuration    | get-bucket-policy
get-bucket-replication                   | get-bucket-request-payment
get-bucket-tagging                       | get-bucket-versioning
get-bucket-website                       | get-object
get-object-acl                           | get-object-torrent
head-bucket                              | head-object
list-buckets                             | list-multipart-uploads
list-object-versions                     | list-objects
list-parts                               | put-bucket-acl
put-bucket-cors                          | put-bucket-lifecycle
put-bucket-logging                       | put-bucket-notification
put-bucket-notification-configuration    | put-bucket-policy
put-bucket-replication                   | put-bucket-request-payment
put-bucket-tagging                       | put-bucket-versioning
put-bucket-website                       | put-object
put-object-acl                           | restore-object
upload-part                              | upload-part-copy
wait                                     | help

But

get-bucket-lifecycle is working this means my aws is configured :

[root@ADM-PROD-OMNI noc-scripts]# aws s3api get-bucket-lifecycle --bucket 4sm-wrapup
RULES    clear multipart failed files           Enabled

**OR**

[root@ADM-PROD-OMNI noc-scripts]# aws s3api get-bucket-lifecycle --bucket noc-try

A client error (NoSuchLifecycleConfiguration) occurred when calling the GetBucketLifecycle operation: The lifecycle configuration does not exist

Also tried :

 [root@ADM-PROD-OMNI noc-scripts]# aws s3api put-bucket-lifecycle --bucket noc-try --lifecycle-configuration  lifecycle.json

    Error parsing parameter '--lifecycle-configuration': Expected: '=', received: '.' for input:
    lifecycle.json
             ^

Please let me know what is wrong here ?

1
can we see your lifecycle.json?zoubida13
@zoubida13 My lifecycle.json : <LifecycleConfiguration> <Rule> <ID>clear multipart failed files</ID> <Prefix>S3 buckets/</Prefix> <Status>Enabled</Status> <AbortIncompleteMultipartUpload> <DaysAfterInitiation>30</DaysAfterInitiation> </AbortIncompleteMultipartUpload> </Rule> </LifecycleConfiguration>Ashish Karpe

1 Answers

6
votes

In your first example it is pretty obvious that the method "put-bucket-lifecycle-configuration" does not exist, and you need to be using "put-bucket-lifecycle" instead, which you said you also tried and received a different error.

Different errors are good!

The new error suggests improper syntax when calling your .json configuration file, and/or improper structured JSON.

Here is documentation on the "put-bucket-lifecycle": put-bucket-lifecycle

Here is an example of calling a .json config file:

aws s3api put-bucket-lifecycle --bucket my-bucket --lifecycle-configuration file://lifecycle.json

Here is an example of JSON file:

{
  "Rules": [
    {
      "ID": "Move to Glacier after sixty days (objects in logs/2015/)",
      "Prefix": "logs/2015/",
      "Status": "Enabled",
      "Transition": {
        "Days": 60,
        "StorageClass": "GLACIER"
      }
    },
    {
      "Expiration": {
        "Date": "2016-01-01T00:00:00.000Z"
      },
      "ID": "Delete 2014 logs in 2016.",
      "Prefix": "logs/2014/",
      "Status": "Enabled"
    }
  ]
}

BELOW JSON FILE IS TESTED AND WORKS AS SHOWN IN THE SUBSEQUENT SCREENSHOTS:

{
    "Rules": [
        {
          "ID": "multipart-upload-rule",
          "Prefix": "noc-try",
          "Status": "Enabled",
          "AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 3 }
        }
    ]
}

CLI COMMAND TO CREATE LIFECYCLE CONFIG USING ABOVE JSON FILE:

aws s3api put-bucket-lifecycle --bucket testbucket1478921 --lifecycle-configuration file://c:/tmp/test.json

enter image description hereenter image description hereenter image description here