AWS S3 Redirection rules not letting me saving it

Viewed 6433

I tried to create an image resizer lambda function and for that I use S3 bucket for storage, but when I try to add Redirection rules under S3 properties it does not allow me to save it. It keep giving me error

(Unknown Error
An unexpected error occurred.
API response
Expected params.WebsiteConfiguration.RoutingRules to be an Array)

this is the redirect rule I'm trying to add

<RoutingRules>
    <RoutingRule>
        <Condition>
            <KeyPrefixEquals/>
            <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
        </Condition>
        <Redirect>
            <Protocol>https</Protocol>
            <HostName>API-endpoint</HostName>
            <ReplaceKeyPrefixWith>prod/resize?key=</ReplaceKeyPrefixWith>
            <HttpRedirectCode>307</HttpRedirectCode>
        </Redirect>
    </RoutingRule>
</RoutingRules>
3 Answers

GOT IT WORKING

Following definition works:

[
    {
        "Condition": {
            "HttpErrorCodeReturnedEquals": "404"
        },
        "Redirect": {
            "Protocol": "https",
            "HostName": "<host>",
            "ReplaceKeyPrefixWith": "<prefix>",
            "HttpRedirectCode": "307"
        }
    }
]

To create redirection rules in the new Amazon S3 console, you must use JSON.

Go to the S3 console and select your bucket. Select the Permission tab. Then go to the Bucket policy. push the edit button and add the following to the Bucket policy. Then replace your bucket name with Your_Bucket_Name

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "AllowPublicReadAccess",
        "Effect": "Allow",
        "Principal": "*",
        "Action": "s3:GetObject",
        "Resource": "arn:aws:s3:::Your_Bucket_Name/*"
    }
]}
Related