Rewrite URLs for an S3 hosted site

0

I'm currently hosting a React site on S3 with CloudFront. One of the URLs used currently looks like this: https://example.org/submit/${token}. As token varies in length, it sometimes means that the total URL can be longer than the S3 limit of 1024. To get around this I'd like to change to a new URL system so that the same route is now located at https://example.org/submit?token=${token} (I assume the query string doesn't count towards the key length limit). This is easy enough to do but I'd like to maintain backwards compatibility with the old route format.

Is there some way that I can rewrite the URL of requests in the old format to be in the new format? It doesn't look like the S3 redirect rules are flexible to allow this, but can it be done in CloudFront instead?

MorayM
demandé il y a 3 mois243 vues
3 réponses
0

If you're using CloudFront and want to transform the request, Lambda@Edge is a great option. [1]

[1] Lambda@Edge example functions - Working with query strings - examples - https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-examples.html#lambda-examples-query-string-examples

profile pictureAWS
répondu il y a 3 mois
0

Take a look at this workshop, shows how to do this with Lambda@Edge and CloudFront Functions.

Handling Rewrites and Redirects using Edge Functions

profile pictureAWS
EXPERT
kentrad
répondu il y a 3 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions