(aws-amplify): Cannot update app with custom rules
See original GitHub issueWhat 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:
- Created 2 years ago
- Comments:12 (11 by maintainers)
Top GitHub Comments
Issue has been fixed according to team, ping me if you are still experiencing the issue
Apologies for not being clear, looking back I didn’t ever tell you any real information 😅