amplify-hosting icon indicating copy to clipboard operation
amplify-hosting copied to clipboard

Saving rewrites and redirects to configuration file?

Open patleeman opened this issue 5 years ago • 31 comments

** Please describe which feature you have a question about? ** Rewrites and Redirects

** Provide additional details** I plan on having a bunch of rewrites and redirects and would feel more secure if I could save them in my repository. Is it possible to have the rewrite data saved in a config file like the amplify.yml file?

patleeman avatar Jul 26 '19 16:07 patleeman

Another benefit of this approach is the rewrites & redirects can differ per connected branch, which can be helpful as things change over time.

smakinson avatar Sep 06 '19 20:09 smakinson

Oh and if possible in this process it would also be nice if env vars can be referenced somehow in the rewrites so that secret things can be left in the env vars as usual.

smakinson avatar Sep 06 '19 21:09 smakinson

We are experiencing the same issue, it would be great if we can limit the scope of the rewrites and redirects by branch.

Another benefit of this approach is the rewrites & redirects can differ per connected branch, which can be helpful as things change over time.

dbrunet73 avatar Oct 15 '19 12:10 dbrunet73

@smakinson @dbrunet73 if you would like to setup redirects per branch, one workaround is to create two amplify console apps and re-connect the same repo: you will be able to setup different redirects then.

swaminator avatar Dec 02 '19 07:12 swaminator

@swaminator I'm looking at using a reverse proxy rewrite to point to proxy a rest api url and the url format is:

https://{restapi_id}.execute-api.{region}.amazonaws.com/{stage_name}/

since stage_name needs to be provided I would like to be able to proxy the dev stage_name in the dev environment and the prod stage_name in the prod environment, etc. Perhaps this feature request could solve this? Or maybe we need a similar override option like the env vars have? Or maybe I'm just missing how to do it? 😄

smakinson avatar Mar 11 '20 21:03 smakinson

By the way, after taking a pause on checking out Amplify console and coming back to it only months later, it's encouraging to see the good progress being made. Thanks for the hard work.

smakinson avatar Mar 12 '20 14:03 smakinson

This would be a helpful feature to manage this configuration with the rest of the application instead of tweaking things on a config page.

ocie avatar Jun 28 '20 01:06 ocie

This is super important for agile workflows, please prioritize. thanks!

adamJLev avatar Jul 17 '20 14:07 adamJLev

Great idea here - this would simplify on-boarding new members who don't need access to AWS.

araphiel avatar Aug 04 '20 19:08 araphiel

Currently the best option it to do this via CDK

michaelbrewer avatar Nov 06 '20 05:11 michaelbrewer

It would be beneficial to have it within the amplify development workflow.

chrisyeung1121 avatar Jan 25 '21 15:01 chrisyeung1121

FYI: Netlify has two ways to configure rewrites and redirects.

Rewrites and redirects specific config file _redirects and general config file netlify.toml. I would like to see the same mechanism as Netlify's _redirects introduced to AWS.

Here is a _redirects example:

# Redirects from what the browser requests to what we serve
/home              /
/blog/my-post.php  /blog/my-post
/news              /blog
/cuties            https://www.petsofnetlify.com

teppeis avatar Jan 26 '21 07:01 teppeis

Any updates on this? I saw mentioned in the other ticket that this is on the roadmap :)

adamJLev avatar Feb 24 '21 21:02 adamJLev

It would be super helpful to manage redirects and rewrites through a configuration file.

brettdewoody avatar Mar 06 '21 00:03 brettdewoody

I have a project with a large number of redirects (~3000). This would be most helpful to be able to manage redirects from a config file in the project vs. the amplify console/CDK. Looking forward to seeing updates on this.

h2ouw8n4 avatar Mar 15 '21 12:03 h2ouw8n4

@dmuensterman I pity you. That's a ton of rewrites.....

boatcoder avatar Mar 24 '21 22:03 boatcoder

@boatcoder you are telling me! I'm working on getting them cleaned up. It was autogenerated from a shopify site. So everytime they changed blog tags and stuff, shopify would spit out a bunch...

h2ouw8n4 avatar Mar 24 '21 23:03 h2ouw8n4

amplify.yml for build settings per branch. customHttp.yml for header rules per branch. Environment Variables can have variable overrides for branches.

No options for redirects and rewrites? This forces us to push changes directly and immediately into our production applications which is high risk. We need a way to test pre-production environments.

This feature would be very valuable.

jasonrundell avatar May 10 '21 21:05 jasonrundell

+1 on this issue.

For the sake of DX and productivity, it would make a LOT of sense for users/customers to be able to specify rewrites somewhere within the "amplify development workflow" (not needing to use CDK/CFN, or needing access to Amplify Console) by specifying rewrites directly in a config/yaml file, like @jasonrundell mentioned.

From a "have we seen this before" perspective, this would be a familiar pattern for many people - since we've all seen .htaccess files before, and they fundamentally serve the same function. It would be great to have, and easy to understand.

Being able, also, to specify branch-specific rewrites would be a major +1 stretch-goal.

armenr avatar Jul 27 '21 19:07 armenr

Another comment on DX - would be an awesome outcome (if a stretch goal) if we could configure SPA apps easily, so:

</^[^.]+$|\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json|webp)$)([^.]+$)/> reeduicrecting to index.html with status 200 by declaring something simple like spa.

tomharvey avatar Jun 15 '22 08:06 tomharvey

+1 on this. Managing multiple projects via console is not easiest way to go. Please add ability to allow defining redirect via some file e.g. redirects.yml or as a section inside amplify.yml.

yuyokk avatar Sep 21 '22 13:09 yuyokk

This is a much needed feature. Accessing the web console for this appears unnecessary. Amplify has come a long way, and this just appears to be something easy, as the web console already supports it.

ghost avatar Nov 30 '22 07:11 ghost

I'd encourage people to use a Terraform or CDK setup and handle this with a CustomRule

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_app#example-usage

araphiel avatar Nov 30 '22 15:11 araphiel

I'd encourage people to use a Terraform or CDK setup and handle this with a CustomRule

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_app#example-usage

^^ This can be achieved with a simple custom resource that plugs right into Amplify + a straightforward CloudFormation template. Not a bad idea, actually. 👍🏼

armenr avatar Dec 01 '22 13:12 armenr

I'd encourage people to use a Terraform or CDK setup and handle this with a CustomRule https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_app#example-usage

this is valid point but for most cases where I want to use Amplify to host static site via connect to Github repo (similar to what Netlify does) setting up a CDK or Terraform is overkill. Amplify should provide "config" file where these basic things can be defined (again Netlify as an example with their netlify.toml file)

yuyokk avatar Dec 01 '22 14:12 yuyokk

2nd this and any guidance for a work around would be appreciated.

vaughngit avatar Jun 08 '23 22:06 vaughngit

Hi team, any news for this feature?

nam-truong-le avatar Jun 27 '23 07:06 nam-truong-le

IDK if this thread is dead or has been fixed differently.

I have had some success doing the following:

  1. Create/Update routes in a file called customRules.json in the root of the repo with all the rewrites/redirects in it.
    [
      {
        "source": "/<*>",
        "status": "404-200",
        "target": "/index.html"
      },
      .... other rewrites/redirects....
    ]
    
  2. Run the following command to update Rewrites and Redirects for an app
    aws amplify update-app --app-id YOUR_APP_ID --custom-rules file://customRules.json
    

It's still a manual step, but is less painful than using the Web GUI for a large number of entries, keeps a record in git, and is easier to use between multiple apps.

aghos7 avatar Jun 28 '24 15:06 aghos7