question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-amplify): Cannot update app with custom rules

See original GitHub issue

What is the problem?

When updating our CDK stack with an Amplify App to have additional custom rules for redirects the CloudFormation call failed with the inability to update the Amplify app. (See what actually happened).

Reproduction Steps

Create and deploy an Amplify app with a custom rule, branch and source code provider (in this case GitHub):

const app = new App(this, "MyApp", {
  sourceCodeProvider: new GitHubSourceCodeProvider({
    owner: "aws",
    repository: "aws-cdk",
    oauthToken: token,
  })
});

const branch = app.addBranch("branch", {
  branchName: "master",
  pullRequestPreview: false
  autoBuild: true
});

app.addCustomRule({
  source:
    "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json)$)([^.]+$)/>",
  target: "/index.html",
  status: RedirectStatus.REWRITE,
});

Update CDK with new rules and deploy:

const app = new App(this, "MyApp", {
  sourceCodeProvider: new GitHubSourceCodeProvider({
    owner: "aws",
    repository: "aws-cdk",
    oauthToken: token,
  })
});

const branch = app.addBranch("branch", {
  branchName: "master",
  pullRequestPreview: false
  autoBuild: true
});

app.addCustomRule({
  source: "/url",
  target: "https://github.com/aws/aws-cdk",
  status: RedirectStatus.PERMANENT_REDIRECT,
});
app.addCustomRule({
  source:
    "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|woff2|ttf|map|json)$)([^.]+$)/>",
  target: "/index.html",
  status: RedirectStatus.REWRITE,
});

What did you expect to happen?

The Amplify app should be updated with the additional custom rules as can be done in the AWS Console itself.

What actually happened?

CloudFormation call fails and results in a rollback.

11:02:53 AM | UPDATE_FAILED        | AWS::Amplify::App    | myapp27C0DC47C
Resource handler returned message: "Invalid request provided: There was an issue setting up your reposito
ry. Please try again later.({"message":"Validation Failed","errors":[{"resource":"Hook","code":"custom","
message":"Hook already exists on this repository"}],"documentation_url":"https://docs.github.com/rest/ref
erence/repos#create-a-repository-webhook"}) (Service: Amplify, Status Code: 400, Request ID: be7d1bc2-a48
f-49f2-927f-276f88a1e107, Extended Request ID: null)" (RequestToken: 373a2154-0510-40e5-885a-8afe40a6d057
, HandlerErrorCode: InvalidRequest)

CDK CLI Version

1.116.0 (build d04661d)

Framework Version

No response

Node.js Version

14

OS

Windows 10

Language

Typescript

Language Version

TypeScript (3.9.7)

Other information

This is likely not an issue with the CDK itself and is an issue with CloudFormation and Amplify.

The CDK itself generates a valid CloudFormation template for the change above adding the entries of Custom Rules as appropriately defined by the definition https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-amplify-app.html Running a diff showed nothing else changed except the addition of rules.

In fact you can replicate the bug above without using the CDK by writing a CloudFormation template and updating it manually with custom rules.

Given that the issue was first found via the CDK here I am raising it here however (I don’t know where to raise it for CF/Amplify).

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
peterwoodworthcommented, Dec 30, 2021

Issue has been fixed according to team, ping me if you are still experiencing the issue

1reaction
peterwoodworthcommented, Nov 26, 2021

Apologies for not being clear, looking back I didn’t ever tell you any real information 😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

update-app — AWS CLI 1.27.37 Command Reference
The custom redirect and rewrite rules for an Amplify app. (structure). Describes a custom rewrite or redirect rule. source -> (string). The source...
Read more >
Amplify::App CustomRule - AWS CloudFormation
The CustomRule property type allows you to specify redirects, rewrites, and reverse proxies. Redirects enable a web app to reroute navigation from one...
Read more >
UpdateApp - Amplify - AWS Documentation
The custom redirect and rewrite rules for an Amplify app. Type: Array of CustomRule objects. Required: No. description. The description for an Amplify...
Read more >
Configuring build settings - AWS Amplify Hosting
You can configure Amplify to disable automatic builds on every code commit. To set up, choose App settings, General, and then scroll to...
Read more >
Amplify: Update-AMPApp Cmdlet | AWS Tools for PowerShell
You must specify either accessToken or oauthToken when you update an app.Existing Amplify apps deployed from a GitHub repository using OAuth continue to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found