Skip to content

Commit 833a0cb

Browse files
committed
fix(aws-amplify-alpha): clarify GitHub repository configuration to address #25658
1 parent 753ed62 commit 833a0cb

File tree

4 files changed

+106
-23
lines changed

4 files changed

+106
-23
lines changed

Diff for: packages/@aws-cdk/aws-amplify-alpha/README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import * as codebuild from 'aws-cdk-lib/aws-codebuild';
2626

2727
const amplifyApp = new amplify.App(this, 'MyApp', {
2828
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
29-
owner: '<user>',
30-
repository: '<repo>',
31-
oauthToken: SecretValue.secretsManager('my-github-token'),
29+
owner: '<github-username>',
30+
repository: '<repository-name>',
31+
accessToken: SecretValue.secretsManager('my-github-token'),
3232
}),
3333
buildSpec: codebuild.BuildSpec.fromObjectToYaml({
3434
// Alternatively add a `amplify.yml` to the repo
@@ -61,8 +61,8 @@ To connect your `App` to GitLab, use the `GitLabSourceCodeProvider`:
6161
```ts
6262
const amplifyApp = new amplify.App(this, 'MyApp', {
6363
sourceCodeProvider: new amplify.GitLabSourceCodeProvider({
64-
owner: '<user>',
65-
repository: '<repo>',
64+
owner: '<gitlab-namespace-or-group>',
65+
repository: '<repository-name>',
6666
oauthToken: SecretValue.secretsManager('my-gitlab-token'),
6767
}),
6868
});
@@ -158,9 +158,9 @@ Use `BasicAuth.fromCredentials` when referencing an existing secret:
158158
```ts
159159
const amplifyApp = new amplify.App(this, 'MyApp', {
160160
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
161-
owner: '<user>',
162-
repository: '<repo>',
163-
oauthToken: SecretValue.secretsManager('my-github-token'),
161+
owner: '<github-username>',
162+
repository: '<repository-name>', // Just the repository name, NOT the full URL
163+
accessToken: SecretValue.secretsManager('my-github-token'),
164164
}),
165165
basicAuth: amplify.BasicAuth.fromCredentials('username', SecretValue.secretsManager('my-github-token')),
166166
});
@@ -196,9 +196,9 @@ of branches:
196196
```ts
197197
const amplifyApp = new amplify.App(this, 'MyApp', {
198198
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
199-
owner: '<user>',
200-
repository: '<repo>',
201-
oauthToken: SecretValue.secretsManager('my-github-token'),
199+
owner: '<github-username>',
200+
repository: '<repository-name>', // Just the repository name, NOT the full URL
201+
accessToken: SecretValue.secretsManager('my-github-token'),
202202
}),
203203
autoBranchCreation: { // Automatically connect branches that match a pattern set
204204
patterns: ['feature/*', 'test/*'],

Diff for: packages/@aws-cdk/aws-amplify-alpha/lib/app.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,42 @@ export interface IApp extends IResource {
2626
*/
2727
export interface SourceCodeProviderConfig {
2828
/**
29-
* The repository for the application. Must use the `HTTPS` protocol.
29+
* The full HTTPS URL for the repository for the application.
3030
*
31-
* For example, `https://github.com/aws/aws-cdk`.
31+
* For GitHub: `https://github.com/owner/repository`
32+
* For GitLab: `https://gitlab.com/owner/repository`
33+
* For CodeCommit: The HTTPS clone URL
3234
*/
3335
readonly repository: string;
3436

3537
/**
3638
* OAuth token for 3rd party source control system for an Amplify App, used
3739
* to create webhook and read-only deploy key. OAuth token is not stored.
3840
*
39-
* Either `accessToken` or `oauthToken` must be specified if `repository`
40-
* is specified.
41+
* For GitHub repositories, use `accessToken` instead. OAuth tokens for GitHub repositories
42+
* are supported for backward compatibility but we strongly recommend using `accessToken`
43+
* with the Amplify GitHub App.
44+
*
45+
* For other repository providers like Bitbucket or CodeCommit, use `oauthToken`.
46+
*
47+
* Either `accessToken` (GitHub) or `oauthToken` (other providers) must be specified
48+
* when connecting to a source code repository.
4149
*
4250
* @default - do not use a token
51+
* @deprecated For GitHub repositories, use accessToken instead
4352
*/
4453
readonly oauthToken?: SecretValue;
4554

4655
/**
47-
* Personal Access token for 3rd party source control system for an Amplify
48-
* App, used to create webhook and read-only deploy key. Token is not stored.
56+
* Personal Access token for GitHub repository for an Amplify
57+
* App, used to authorize access to a GitHub repository using the Amplify GitHub App.
58+
* Token is not stored.
59+
*
60+
* This is the recommended way to authorize access to GitHub repositories.
61+
* For non-GitHub repositories (GitLab, Bitbucket, CodeCommit), use `oauthToken`.
4962
*
50-
* Either `accessToken` or `oauthToken` must be specified if `repository`
51-
* is sepcified.
63+
* Either `accessToken` (GitHub) or `oauthToken` (other providers) must be specified
64+
* when connecting to a source code repository.
5265
*
5366
* @default - do not use a token
5467
*/

Diff for: packages/@aws-cdk/aws-amplify-alpha/lib/source-code-providers.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,23 @@ export interface GitHubSourceCodeProviderProps {
1717
readonly repository: string;
1818

1919
/**
20-
* A personal access token with the `repo` scope
20+
* Personal Access token for GitHub repository using the Amplify GitHub App.
21+
* Required for new GitHub repositories.
22+
*
23+
* @default - no access token
2124
*/
22-
readonly oauthToken: SecretValue;
25+
readonly accessToken?: SecretValue;
26+
27+
/**
28+
* OAuth token for GitHub repository.
29+
* @deprecated Use accessToken instead. OAuth tokens for GitHub repositories are supported
30+
* for backwards compatibility but we strongly recommend using accessToken with the Amplify GitHub App.
31+
* Existing Amplify apps deployed from a GitHub repository using OAuth continue to work with CI/CD.
32+
* However, we strongly recommend that you migrate these apps to use the GitHub App
33+
* https://docs.aws.amazon.com/amplify/latest/userguide/setting-up-GitHub-access.html#migrating-to-github-app-auth
34+
* @default - no OAuth token
35+
*/
36+
readonly oauthToken?: SecretValue;
2337
}
2438

2539
/**
@@ -31,6 +45,7 @@ export class GitHubSourceCodeProvider implements ISourceCodeProvider {
3145
public bind(_app: App): SourceCodeProviderConfig {
3246
return {
3347
repository: `https://github.com/${this.props.owner}/${this.props.repository}`,
48+
accessToken: this.props.accessToken,
3449
oauthToken: this.props.oauthToken,
3550
};
3651
}
@@ -51,7 +66,7 @@ export interface GitLabSourceCodeProviderProps {
5166
readonly repository: string;
5267

5368
/**
54-
* A personal access token with the `repo` scope
69+
* OAuth token for GitLab repository with the `repo` scope
5570
*/
5671
readonly oauthToken: SecretValue;
5772
}

Diff for: packages/@aws-cdk/aws-amplify-alpha/test/app.test.ts

+56-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,62 @@ beforeEach(() => {
99
stack = new Stack();
1010
});
1111

12-
test('create an app connected to a GitHub repository', () => {
12+
test('create an app connected to a GitHub repository with access token', () => {
13+
// WHEN
14+
new amplify.App(stack, 'App', {
15+
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
16+
owner: 'aws',
17+
repository: 'aws-cdk',
18+
oauthToken: SecretValue.unsafePlainText('secret'),
19+
}),
20+
buildSpec: codebuild.BuildSpec.fromObjectToYaml({
21+
version: '1.0',
22+
frontend: {
23+
phases: {
24+
build: {
25+
commands: [
26+
'npm run build',
27+
],
28+
},
29+
},
30+
},
31+
}),
32+
});
33+
34+
// THEN
35+
Template.fromStack(stack).hasResourceProperties('AWS::Amplify::App', {
36+
Name: 'App',
37+
BuildSpec: 'version: \"1.0\"\nfrontend:\n phases:\n build:\n commands:\n - npm run build\n',
38+
IAMServiceRole: {
39+
'Fn::GetAtt': [
40+
'AppRole1AF9B530',
41+
'Arn',
42+
],
43+
},
44+
OauthToken: 'secret',
45+
Repository: 'https://github.com/aws/aws-cdk',
46+
BasicAuthConfig: {
47+
EnableBasicAuth: false,
48+
},
49+
});
50+
51+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', {
52+
AssumeRolePolicyDocument: {
53+
Statement: [
54+
{
55+
Action: 'sts:AssumeRole',
56+
Effect: 'Allow',
57+
Principal: {
58+
Service: 'amplify.amazonaws.com',
59+
},
60+
},
61+
],
62+
Version: '2012-10-17',
63+
},
64+
});
65+
});
66+
67+
test('create an app connected to a GitHub repository with oauth token', () => {
1368
// WHEN
1469
new amplify.App(stack, 'App', {
1570
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({

0 commit comments

Comments
 (0)