使用脚本设置S3生命周期策略

时间:2018-08-10 09:08:45

标签: bash shell amazon-web-services amazon-s3 scripting

执行以下命令时

aws s3api put-bucket-lifecycle --bucket krishna-s3auto --lifecycle-configuration '{"Rules":[{"Status":"Enabled","Prefix":"","Expiration":{"Days":'90'},"AbortIncompleteMultipartUpload":{"DaysAfterInitiation":'7'},"Transitions":[{"Days":'91'},"StorageClass":"STANDARD_IA"}],"ID":"Kittu"}]}'

我收到以下错误

Error parsing parameter '--lifecycle-configuration': Invalid JSON: Expecting ',' 
  delimiter: line 1 column 168 (char 167)
JSON received:
  {"Rules":[{"Status":"Enabled","Prefix":"","Expiration":{"Days":90},
   "AbortIncompleteMultipartUpload":{"DaysAfterInitiation":7},
   "Transitions":[{"Days":91},"StorageClass":"STANDARD_IA"}],"ID":"Kittu"}]}

1 个答案:

答案 0 :(得分:2)

您的JSON格式不正确,并且还出现了诸如'Transitions'关键字之类的错误,而不是'Transition'

以下命令应该可以解决您的问题

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

以下是您需要放入lifecycle.json文件中的内容

{
  "Rules": [
    {
      "Status": "Enabled",
      "Prefix": "",
      "Expiration": {
        "Days": 90
      },
      "AbortIncompleteMultipartUpload": {
        "DaysAfterInitiation": 7
      },
      "Transition": {
          "Days": 91,
          "StorageClass": "STANDARD_IA"
      },
      "ID": "Kittu"
    }
  ]
}