Skip to content

Commit 31e7ede

Browse files
committed
Code cleanup and docs refactor
1 parent bdb69a7 commit 31e7ede

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

DO_NOT_AUTOTEST

-2
This file was deleted.

README.md

+29-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ The domain for the static site (i.e. mystaticsite.com) must be configured as a h
3535
npm install
3636
```
3737

38+
### Create GitHub token
39+
40+
Follow the instructions [here](https://docs.aws.amazon.com/codepipeline/latest/userguide/GitHub-authentication.html) and make sure to use the `CLI` instructions
41+
as you need a `personal access token` to authenticate with `cdk`
42+
43+
### Upload your github token to SSM
44+
45+
Once you have your token you have to upload it to ssm (preferably in the
46+
same region as the stack).
47+
48+
> Make sure to use the `plaintext` option and NOT the key value pair.
49+
3850
### Create AWS Service Role
3951

4052
You need to create a service role that both `cloudformation` and `codebuild`
@@ -70,19 +82,34 @@ Here's an example for the trust relationship policy:
7082
}
7183
```
7284

85+
> Once you have the value above edit [index.ts](./index.ts) with the required values
86+
87+
### [optional] Context
88+
89+
Edit [cdk.json](./cdk.json) with your `domain` and `subdomain`
90+
7391
## Build
7492

7593
```
7694
npm run build
7795
```
7896

79-
## Deploy
97+
## Deploy the Pipeline
8098

8199
```
82100
./node_modules/.bin/cdk deploy --profile <your_aws_profile>
83101
```
84102

85-
> Optionally provide which stack to deploy
103+
> The static site is deployed automatically after a git commit
104+
> Make sure you trigger the pipeline after the deployment
105+
106+
107+
## Test the Pipeline
108+
109+
Edit [site-contents/index.html](./site-contents/index.html) and commit the changes
110+
Then go to your subdomain.domain and see the changes deployed.
111+
112+
> you can see the progress of the pipeline in the AWS Code Pipeline console
86113
87114
---
88115

cdk.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"app": "node index",
33
"context": {
4-
"domain": "ginienterprise-dev.com",
5-
"subdomain": "test-cdk"
4+
"domain": "mystaticsite.com",
5+
"subdomain": "www"
66
}
77
}

index.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,26 @@ import cdk = require('@aws-cdk/core');
33
import { StaticSite } from './static-site';
44
import { Pipeline } from './pipeline';
55

6+
// Configuration
7+
const appName = 'MyStaticSite'
8+
// aws
9+
const awsAccount = '';
10+
const awsRegion = 'us-east-1'
11+
const awsServiceRoleName = 'ServiceRoleCloudFormationAdminAccess'
12+
// github token
13+
const sourceToken = 'github-token-xxxxx'
14+
615
const app = new cdk.App();
716

817
/**
918
* This stack relies on getting the domain name from CDK context.
10-
* Use 'cdk synth -c domain=mystaticsite.com -c subdomain=www -c account=account_id'
19+
* Use 'cdk synth -c domain=mystaticsite.com -c subdomain=www'
1120
* Or add the following to cdk.json:
1221
* {
1322
* "context": {
1423
* "domain": "mystaticsite.com",
1524
* "subdomain": "www",
16-
* "account": "aws_account_id"
25+
* "account": "awsAccount_id"
1726
* }
1827
* }
1928
**/
@@ -33,20 +42,20 @@ class PipelineStack extends cdk.Stack {
3342
super(parent, name, props);
3443

3544
new Pipeline(this, 'Pipeline', {
36-
sourceToken: 'github-token-ricardosllm',
37-
cfnTemplate: 'MyStaticSite.template.json',
38-
serviceRole: 'arn:aws:iam::191560372108:role/ServiceRoleCloudFormationAdminAccess'
45+
sourceToken,
46+
cfnTemplate: appName + '.template.json',
47+
serviceRole: 'arn:aws:iam::' + awsAccount + ':role/' + awsServiceRoleName
3948
});
4049
}
4150
}
4251

43-
new MyStaticSiteStack(app, 'MyStaticSite', {
44-
env: { region: 'us-east-1', account: '191560372108' }
52+
new MyStaticSiteStack(app, appName, {
53+
env: { region: awsRegion, account: awsAccount }
4554

4655
});
4756

4857
new PipelineStack(app, 'PipelineMyStaticSite', {
49-
env: { region: 'us-east-1', account: '191560372108' }
58+
env: { region: awsRegion, account: awsAccount }
5059
})
5160

5261
app.synth();

0 commit comments

Comments
 (0)