Bug: AWS Amplify redirect design issue

0

Description

I was trying to contribute to a project.

This page describes how to set-up a Reverse Proxy https://docs.aws.amazon.com/amplify/latest/userguide/redirect-rewrite-examples.html#reverse-proxy-rewrite

It says, that you can just set-up this at console.aws.amazon.com/amplify/apps/d7av09y16w3z4/redirects:

[
  {
    "source": "/images/<*>",
    "status": "200",
    "target": "https://images.otherdomain.com/<*>",
    "condition": null
  }
]

Now. It happens that you can add multiple domains on an AWS Amplify App. But the redirect rewrite feature, seems to only prioritize the first main domain, which sounds problematic.

For example.

You could have images.otherdomain.com and example.images.otherdomain.com. Both will show an entry on the table at "Custom Domains".

 

So, now I want to ask.

How do you make https://example.images.otherdomain.com/<*> point to https://images.otherdomain.com/images/example/<*> ?

So, the other way around.

 

Re-production Steps

  1. Create a GitHub Repository and put in some folder structure with files.
  2. Launch it to AWS Amplify
  3. Now add two custom domain.
  4. Go to console.aws.amazon.com/amplify/apps/<some-id>/redirects
  5. Now copy paste this in there
[
  {
    "source": "https://example.images.otherdomain.com/<*>",
    "status": "200",
    "target": "https://images.otherdomain.com/images/example/<*>",
    "condition": null
  }
]
  1. Click "Save"
  2. Try going to https://example.images.otherdomain.com/text.txt assuming you have a file at https://images.otherdomain.com/images/example/text.txt
  3. Observe

 

Expected Result

When you go to https://example.images.otherdomain.com/text.txt it should rewrite to https://images.otherdomain.com/images/example/text.txt.

 

Actual Result

It doesn't work. But the site shows you that you can redirect multiple domains added to one AWS Amplify App. However, THIS specific case doesn't work.

 

Please fix :)

1 Answer
1
Accepted Answer

The issue you're experiencing with AWS Amplify's redirect and rewrite rules is related to how Amplify handles multiple domains and the limitations of its current redirect configuration system.

Amplify's redirect and rewrite rules are primarily designed to work within the context of a single domain. When you have multiple custom domains set up for an Amplify app, the redirect rules typically apply to the primary domain by default.

In your specific case, where you want to redirect from one custom domain (example.images.otherdomain.com) to a different path on another custom domain (images.otherdomain.com/images/example/), this is not directly supported by Amplify's built-in redirect rules.

To achieve the desired result, you might need to consider alternative approaches:

  1. Use a custom server-side solution: Implement a custom server-side logic (e.g., using AWS Lambda@Edge with CloudFront) to handle the redirection between your custom domains.

  2. Leverage CloudFront: If possible, set up a CloudFront distribution in front of your Amplify app and use CloudFront's more flexible URL rewriting capabilities.

  3. Implement client-side redirects: If appropriate for your use case, you could implement JavaScript-based redirects on the client side to handle the domain-specific redirections.

  4. Use separate Amplify apps: Consider creating separate Amplify apps for each custom domain if they require significantly different routing rules.

It's worth noting that while Amplify's redirect feature is powerful for many use cases, it has limitations when dealing with complex multi-domain scenarios like yours. You may want to consider submitting a feature request to the AWS Amplify team for better support of cross-domain redirects within a single Amplify app.

For now, the most reliable solution would likely involve using additional AWS services like CloudFront or Lambda@Edge to achieve the desired redirection behavior across your multiple custom domains.
Sources
I getting the 301 issue while deploy my code in the aws amplify | AWS re:Post
amplify redirect rules | AWS re:Post
AWS Amplify redirect from/to custom domain | AWS re:Post

profile picture
answered a month ago
profile pictureAWS
EXPERT
reviewed 22 days ago
  • Thanks.

    How does one make a feature request to the AWS Amplify Team though?

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