I have a set of user folders with the same folder structure, but different content, stored in S3.
/user/userA/application/folder/structure/file.xml
/user/userB/application/folder/structure/file.xml
I would like to redirect the user to a fallback folder, (with fallback content) if the s3 folder structure don't exist for that user yet.
/user-fallback/application/folder/structure/file.xml
I've tried to add a wildcard parameter to my Redirection Rules, but S3 is reading *
as a literal
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>user/*/</KeyPrefixEquals>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith>user-fallback/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
So only urls starting with /user/*/
are being correctly redirected to the user-fallback
folder structure.
I have more than 20 users, so creating individual RoutingRules wouldn't work either (S3 has a routing rule limit)
Any ideas?
In this example, wildcards are used in aws:userid to include all names that are passed by the calling process. For example, the wildcards are used for an application, service, or instance ID when calls are made to obtain temporary credentials. For more information, see Information available in all requests.
You can use the NotPrincipal element of an IAM or S3 bucket policy to limit resource access to a specific set of users. This element allows you to block all users who are not defined in its value array, even if they have an Allow in their own IAM user policies.
This should work:
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>user</KeyPrefixEquals>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith>user-fallback/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With