aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.61k stars 3.91k forks source link

(aws-amplify): Documentation unclear about how to define repository #25658

Open QO-Development opened 1 year ago

QO-Development commented 1 year ago

Describe the bug

I attempt to deploy a new Amplify app via CDK and a GitHubSourceCodeProvider. However, the cdk cli tool errors out and returns an error.

Expected Behavior

I expect the app to deploy properly.

Current Behavior

The error log looks like this:

6:08:08 PM | CREATE_FAILED        | AWS::Amplify::App    | robotofrontendpoc2DD92C8A
Resource handler returned message: "Invalid request provided: The repository url is not valid. (Service: Amplify, Status Code: 400, Request ID: d1855b7d-af69-49cf-8a3d-d36bb9b2b
f94)" (RequestToken: ecae955c-6832-d147-8866-154359ac31d1, HandlerErrorCode: InvalidRequest)

 ❌  WebUiPocStack failed: Error: The stack named WebUiPocStack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: Resource handler returned message: "Invalid request provided: The repository url is not valid. (Service: Amplify, Status Code: 400, Request ID: d1855b7d-af69-49cf-8a3d-d36bb9b2bf94)" (RequestToken: ecae955c-6832-d147-8866-154359ac31d1, HandlerErrorCode: InvalidRequest)
    at FullCloudFormationDeployment.monitorDeployment (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:397:10236)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async deployStack2 (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:400:145739)
    at async /opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:400:128776
    at async run (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:400:126782)

 ❌ Deployment failed: Error: Stack Deployments Failed: Error: The stack named WebUiPocStack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: Resource handler returned message: "Invalid request provided: The repository url is not valid. (Service: Amplify, Status Code: 400, Request ID: d1855b7d-af69-49cf-8a3d-d36bb9b2bf94)" (RequestToken: ecae955c-6832-d147-8866-154359ac31d1, HandlerErrorCode: InvalidRequest)
    at deployStacks (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:400:129083)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async CdkToolkit.deploy (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:400:147788)
    at async exec4 (/opt/homebrew/lib/node_modules/aws-cdk/lib/index.js:455:51984)

Stack Deployments Failed: Error: The stack named WebUiPocStack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: Resource handler returned message: "Invalid request provided: The repository url is not valid. (Service: Amplify, Status Code: 400, Request ID: d1855b7d-af69-49cf-8a3d-d36bb9b2bf94)" (RequestToken: ecae955c-6832-d147-8866-154359ac31d1, HandlerErrorCode: InvalidRequest)

Reproduction Steps

const amplifyApp = new amplify.App(this, "frontend-poc", {
       sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
         owner: "my-github-username",
         repository: "https://github.com/my-github-username/repoName",
         oauthToken: SecretValue.unsafePlainText(
           "token for testing goes here"
         ), 
       }),
     });

Possible Solution

This URL looks perfectly valid to me. I cannot find the proper URL format anywhere in any documentation, nor the error message.

Two possible solutions here:

  1. Document the URL correct format somewhere
  2. Tell me what I'm doing wrong in the error message.

Either way, I don't think I should have to guess at the correct string format.

Additional Information/Context

No response

CDK CLI Version

2.79.1

Framework Version

No response

Node.js Version

18.16.0

OS

Ventura 13.3.1

Language

Typescript

Language Version

No response

Other information

No response

stefanfreitag commented 1 year ago

Hi @QO-Development,

the repository URL will be created internally based on the information you would provide in owner and repository properties. Here is the link to the source code where the concatenation happens:

https://github.com/aws/aws-cdk/blob/7373cb9fd35cd4b0ddcbab3837c18babfd8e1b6f/packages/%40aws-cdk/aws-amplify-alpha/lib/source-code-providers.ts#L33

In the GitHubSourceCodeProviderProps documentation there is also the hint to use the name of the repository (and hence not the URL) . Here is the relevant information

Name Type Description
oauthToken🔹 SecretValue A personal access token with the repo scope.
owner🔹 string The user or organization owning the repository.
repository🔹 string The name of the repository.

from the online documentation available here.

Hope this helps a bit.

peterwoodworth commented 1 year ago

Thanks for the reply @stefanfreitag, you're correct 🙂

@QO-Development Do you think it would be more clear if the examples specified something like <repoName> instead of <repo> like what's currently here?

QO-Development commented 1 year ago

Yes, that would be more clear, thank you. But I think the most confusing thing here is the error message, saying the repo URL is invalid. I suppose digging through the source code could have provided a better answer as well, but I think the most helpful thing to do would be to changes the error message. Something like:

GitHubSourceCodeProvider: Computed property repository URL is invalid. Please validate the constructor input props `owner` and `repository`. 
peterwoodworth commented 1 year ago

The error message isn't something we have control over unfortunately. Since CloudFormation asks for a URL, it will provide a message about an invalid URL if the value provided is invalid. We could implement a validation check to make sure the repo provided is a valid repository name

rewardle-jason commented 1 year ago

Could you output the actual url being called as that would make it obvious what the issue is?