Invalid according to Policy: Policy Condition failed: ["eq", "$x-amz-storage-class", "STANDARD_IA"]

663 Views Asked by At

I am trying to specify the storage class for an AWS S3 object (image file) on its upload from a web page post. All works fine without the storage class specification but when I add it to the policy the page redirects to an error page with XML that indicates:

Invalid according to Policy: Policy Condition failed: ["eq", "$x-amz-storage-class", "STANDARD_IA"]

I've tried different values for the storage class such as upper/lower case, STANDARD, STANDARD-IA, etc but nothing seems to work. Any help would be appreciated.

This is the object policy before its encoded:

{
    "expiration": "2040-01-01T00:00:00Z",
    "conditions": [ 
        {"bucket": "dev-image"},
        ["starts-with", "$key", ""],
        {"acl": "private"},
        {"success_action_redirect": "http://localhost/Image.jsp"},
        ["starts-with", "$Content-Type", ""],
        {"x-amz-storage-class": "STANDARD_IA"},              <<<<< Causes Problem
        ["content-length-range", 0, 10485760]
    ]
}
1

There are 1 best solutions below

0
On

The error message is indicating the form fields do not match the policy conditions. The policy conditions must be a 1:1 match with the form fields; they must match in name and value. Adding an input field "x-amz-storage-class" with value "STANDARD_IA" to the form fixes the error.