put-bucket-lifecycle with error Missing required parameter in LifecycleConfiguration.Rules[0]: "Prefix"
Describe the bug
Hi, There is an issue with AW CLI and put-bucket-lifecycle related to the prefix property. According to the AWS S3 API Prefix is deprecated (here).
Expected Behavior
put-bucket-lifecycle succeeded.
Current Behavior
put-bucket-lifecycle fails.
Reproduction Steps
- I tried to run:
aws s3api put-bucket-lifecycle --bucket <bucket-name> --lifecycle-configuration file://lifecycle.json - lifecycle.json is:
{
"Rules": [
{
"ID": "Clean bucket",
"Status": "Enabled",
"Expiration": {
"Days": 1
}
}
]
}
- The error is:
Parameter validation failed:
Missing required parameter in LifecycleConfiguration.Rules[0]: "Prefix"
I also tried this: 2. lifecycle.json is:
{
"Rules": [
{
"ID": "Clean bucket",
"Status": "Enabled",
"Filter": {
"Prefix": "project"
},
"Expiration": {
"Days": 1
}
}
]
}
- The error is:
Missing required parameter in LifecycleConfiguration.Rules[0]: "Prefix"
Unknown parameter in LifecycleConfiguration.Rules[0]: "Filter", must be one of: Expiration, ID, Prefix, Status, Transition, NoncurrentVersionTransition, NoncurrentVersionExpiration, AbortIncompleteMultipartUpload
Possible Solution
No response
Additional Information/Context
No response
CLI version used
aws-cli/2.8.7
Environment details (OS name and version, etc.)
MacOS
Hi @shirady, thanks for reaching out. I'd recommend that you update to a more recent version of the CLI, and try that operation again. 2.8.7 is very, very out of date, and that's a likely reason for parameter validation errors like this one.
Hi @RyanFitzSimmonsAK,
I updated the version (aws-cli/2.15.10 Python/3.11.7 Darwin/23.0.0 source/arm64 prompt/off) and I still have this issue. I also tried to use the file created in the terminal by running:
cat > life-cycle-policy.json << EOF
{
"Rules": [
{
"Expiration": {
"Days": 1
},
"ID": "cleanbucket",
"Filter": {
"Prefix": ""
},
"Status": "Enabled"
}
]
}
EOF
and then: aws s3api put-bucket-lifecycle --bucket <bucet-name> --lifecycle-configuration file://lcpolicy.json
And still have:
Parameter validation failed: Missing required parameter in LifecycleConfiguration.Rules[0]: "Prefix" Unknown parameter in LifecycleConfiguration.Rules[0]: "Filter", must be one of: Expiration, ID, Prefix, Status, Transition, NoncurrentVersionTransition, NoncurrentVersionExpiration, AbortIncompleteMultipartUpload
I also tried to add policy with the console, get it, and put it with AWS CLI, and still it throws the same error.
BTW, would you please update the example in your documentation put-bucket-lifecycle in AWS CLI, to your API (Prefix should be inside Filter, here).
@shirady I encountered the same issue. The "put-bucket-lifecycle" command has been depreciated, so while it's still available, it only accepts the older lifecycle policy format that doesn't include filter statements.
Try using the same syntax and JSON file, but replace "put-bucket-lifecycle" with "put-bucket-lifecycle-configuration", which will accept the filter statements and should pass validation.
@shirady I encountered the same issue. The "put-bucket-lifecycle" command has been depreciated, so while it's still available, it only accepts the older lifecycle policy format that doesn't include filter statements.
Try using the same syntax and JSON file, but replace "put-bucket-lifecycle" with "put-bucket-lifecycle-configuration", which will accept the filter statements and should pass validation.
I tried using put-bucket-lifecycle-configuration and I get no error, however it does not apply the configuration provided. When I use get-bucket-lifecycle-configuration subsequently I see that the configuration has not changed.
I tried using
put-bucket-lifecycle-configurationand I get no error, however it does not apply the configuration provided. When I useget-bucket-lifecycle-configurationsubsequently I see that the configuration has not changed.
It sounds like you may be encountering a different issue. Can you provide a sanitized copy of the JSON you're attempting to apply?
@shirady I encountered the same issue. The "put-bucket-lifecycle" command has been depreciated, so while it's still available, it only accepts the older lifecycle policy format that doesn't include filter statements.
Try using the same syntax and JSON file, but replace "put-bucket-lifecycle" with "put-bucket-lifecycle-configuration", which will accept the filter statements and should pass validation.
This is correct.
I tried using put-bucket-lifecycle-configuration and I get no error, however it does not apply the configuration provided. When I use get-bucket-lifecycle-configuration subsequently I see that the configuration has not changed.
I was not able to reproduce this behavior. I was able to successfully apply the lifecycle policy mentioned here in your earlier comment using put-bucket-lifecycle-configuration. Could you provide debug logs of that behavior? You can get debug logs by adding --debug to your input, and redacting any sensitive information. Thanks!
Greetings! It looks like this issue hasn’t been active in longer than five days. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one.