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?

3 Risposte
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
con risposta 3 mesi fa
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
ESPERTO
kentrad
con risposta 3 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande