I'm trying to configure this website routing rule for my static s3 bucket website using serverless yaml which uses cloudformation.
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals/>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<Protocol>https</Protocol>
<HostName>foo.amazonaws.com</HostName>
<ReplaceKeyPrefixWith>prod/photos/resize?key=</ReplaceKeyPrefixWith>
<HttpRedirectCode>307</HttpRedirectCode>
</Redirect>
</RoutingRule>
</RoutingRules>
How do I translate that to my yaml below?
resources:
Resources:
UploadBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${file(./serverless.env.yml):${opt:stage}.BucketName}
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
RoutingRule: //What's the format that goes here?
RoutingRules is a list of Amazon S3 Website Configuration Routing Rules Property.
E.g.
RoutingRules:
- RedirectRule:
HostName: foo.amazonaws.com
HttpRedirectCode: "307"
Protocol: https
ReplaceKeyPrefixWith: prod/photos/resize?key=
RoutingRuleCondition:
HttpErrorCodeReturnedEquals: "404"
If anyone interested, here is the JSON representation of the same settings
"WebsiteConfiguration" : {
"IndexDocument": "index.html",
"ErrorDocument": "error.html",
"RoutingRules": [{
"RedirectRule": {
"HostName": {
"foo.amazonaws.com"
},
"HttpRedirectCode": "307",
"ReplaceKeyPrefixWith": "prod/photos/resize?key="
},
"RoutingRuleCondition": {
"HttpErrorCodeReturnedEquals": "404"
}
}]
}