Amplify Hosting Redirects

0

I have moved a NextJS app from a Serverless Framework to Amplify Hosting. Previously the app was behind Cloudfront and I was able to configure geographic access limits which would allow a 403 redirect to a maintenance page. These can be allow or disallow.

I can see the redirect functionality but I am missing two elements

  1. I cannot see how I can set the redirects to being branch-specific. e.g. production goes into maintenance but qa not.
  2. The country codes would enable the redirect. Where is there a list of valid country codes and is there a way of setting something like NOT <US>? I would like allow more than one country at a time. Separate rules or a list of country codes.

I am guessing that this just writes to a .htaccess file? Having a look around that I cannot see the country codes.

Is there a way of "getting at" the underlying cloudfront service to tweak stuff like this?

Thanks,

O.

1 Answer
0

Hi Owain, thanks for asking this question! To address your points:

  1. The Rewrites and redirects settings apply to all branches configured within an app at the moment. Have you considered hosting two Amplify Apps in your account to be able to configure these separately? You can consider opening a Feature Request against the amplify-hosting project or commenting one of the existing issues about geo restriction like this one.
  2. While there is no NOT operator for the list of countries, you can specify a list of alternatives as a condition of a rule - please see the example below. Again, you can consider opening a feature request in the same repo to add this kind of syntax to the rewriting engine to help Amplify team prioritise their work.
[
    {
        "source": "/<*>",
        "target": "/error.html",
        "status": "200",
        "condition": "<IN>|<AE>|<DE>|<HK>" [add all countries except US]
    }
]

Amplify Hosting is a fully managed service, so you don't get access to the underlying CloudFront distribution.

AWS
Piotrek
answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions