aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
448 stars 113 forks source link

Saving rewrites and redirects to configuration file? #18

Open patleeman opened 4 years ago

patleeman commented 4 years ago

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?

smakinson commented 4 years ago

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

smakinson commented 4 years ago

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.

dbrunet73 commented 4 years ago

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.

swaminator commented 4 years ago

@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.

smakinson commented 4 years ago

@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 commented 4 years ago

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.

ocie commented 4 years ago

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

adamJLev commented 3 years ago

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

araphiel commented 3 years ago

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

michaelbrewer commented 3 years ago

Currently the best option it to do this via CDK

chrisyeung1121 commented 3 years ago

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

teppeis commented 3 years ago

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
adamJLev commented 3 years ago

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

brettdewoody commented 3 years ago

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

h2ouw8n4 commented 3 years ago

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.

boatcoder commented 3 years ago

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

h2ouw8n4 commented 3 years ago

@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...

jasonrundell commented 3 years ago

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.

armenr commented 2 years ago

+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.

tomharvey commented 2 years ago

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.

yuyokk commented 1 year ago

+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.

ghost commented 1 year ago

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.

araphiel commented 1 year ago

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

armenr commented 1 year ago

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. 👍🏼

yuyokk commented 1 year ago

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)

vaughngit commented 1 year ago

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

nam-truong-le commented 1 year ago

Hi team, any news for this feature?

aghos7 commented 1 week ago

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.