Skip to content

Commit f7e3141

Browse files
author
amazon-meaisiah
committed
Automate workflow better, remove redundant aws-sdk dependencies
1 parent c648528 commit f7e3141

28 files changed

+560
-371
lines changed

.cfnlintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
templates: ['cloudformation/template.yaml']
2+
include_checks: ['I']
3+
#regions: ['ALL_REGIONS']

BUILDING.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Development guide
2+
3+
Note: this is for advanced users who want to modify the developer portal code itself.
4+
5+
## Getting Started
6+
7+
1. Install each of these if you haven't already:
8+
9+
- [Git](https://git-scm.com/)
10+
- [Node](https://nodejs.org/en/download/) v12 or later
11+
- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)
12+
- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html)
13+
- [CloudFormation Linter](https://github.com/aws-cloudformation/cfn-python-lint)
14+
15+
2. Clone this repo to your local drive.
16+
17+
3. Create a private S3 bucket for putting zipped lambda functions and zipped templates in. Note the bucket name for the next step. (This can be the same one you used during in the initial deployment.)
18+
19+
4. Create a `/dev-portal/deployer.config.js` file. We recommend using the same values you used during the initial deployment.
20+
21+
- If you're just building this to release it locally and a fresh environment isn't needed, you can just copy `/dev-portal/example-deployer.config.js` and fill it in locally.
22+
- If you need to develop in a fresh environment (say, for contributing back to the developer portal or for some more advanced customization), you can customize this further, and you may find `/dev-portal/example-dev-deployer.config.js` as an easier starting point. The fields are the same, just you can switch between deployments far more easily.
23+
- You can put this elsewhere and pass `DEPLOYER_CONFIG=/path/to/deployer.config.js` as an environment variable each time you run a task that uses it, in case you would prefer to manage it outside the repo.
24+
25+
5. Run `node run install release`. This will install everything (the `install`), build the static assets for the first time (the `build` part of `release`), and deploy them (the `deploy` part of `release`).
26+
27+
6. Run `node run start` to start the local development server at `http://localhost:3000`. This also fetches the config from the live website so everything's hooked up correctly. (You can do both this and the previous step in one go via `node run install release start`.)
28+
29+
7. If you created the stack for the first time (or changed the `n` from the development `deployer.config.js` example), you'll need to register a new admin account. In the dev portal, register it as an ordinary user, then go into the Cognito user pool generated for it (you can find it by going to the deployed stack in CloudFormation and searching for "CognitoUserPool" in the "Logical ID" column), search for the account in question (by email is easiest), open it, and add it to the admin group (look for `${STACK_NAME}AdminsGroup`).
30+
31+
8. Make changes locally, test them at `http://localhost:3000`, and, when satisfied, run `npm run release` to build and upload the changes to your cloud dev portal.
32+
33+
## npm Scripts
34+
35+
You can run each of these via `node run ${TASK}`, and you can run multiple together like `node run build deploy`. You can pass options via `node run ${TASK} --key=value` as applicable.
36+
37+
### `node run build`
38+
39+
Builds a production-quality build and copies it to the lambda uploader.
40+
41+
### `node run deploy`
42+
43+
Starts a `sam package` and `sam deploy`, and on success does `node run write-config`. Does not build on its own, though.
44+
45+
### `node run reset-assets`
46+
47+
Resets the static assets to what was last committed to Git. Mainly useful when you want to update a development deployment.
48+
49+
### `node run release`
50+
51+
Synonymous with `node run build deploy reset-assets`, as that's a common operation.
52+
53+
### `node run start`
54+
55+
Gets the output from the CFN stack, writes a local version of the config.js file, and starts up the local development server.
56+
57+
## Notes on static assets
58+
59+
The static assets are only re-uploaded on deployment if the previous deployment and the current deployment were provided different `StaticAssetRebuildToken` parameters. The `npm run deploy` script automatically creates a unique `StaticAssetRebuildToken` for you based on the current date.

dev-portal/README.md

-147
This file was deleted.

dev-portal/example-deployer.config.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// 1. Replace your-lambda-artifacts-bucket-name with the name of the bucket you created in step 3
2+
// of the dev setup.
3+
// 2. Then, replace 'custom-prefix-' in siteAssetsBucket and apiAssetsBucket with your name, your
4+
// org name, or some other unique identifier.
5+
//
6+
// The resulting bucket names must be globally unique.
7+
module.exports = {
8+
// Required, bucket must be pre-made
9+
buildAssetsBucket: 'YOUR_LAMBDA_ARTIFACTS_BUCKET_NAME',
10+
11+
// Required, created by stack
12+
stackName: 'dev-portal',
13+
siteAssetsBucket: 'CUSTOM_PREFIX-dev-portal-static-assets',
14+
apiAssetsBucket: 'CUSTOM_PREFIX-dev-portal-artifacts',
15+
16+
// Required, turns on cognito hosted sign in/sign up UI
17+
cognitoDomainName: 'CUSTOM_PREFIX-auth',
18+
19+
// Optional values (uncomment and change values if you want to use them)
20+
21+
// Change the name of the customers table. Useful for multiple stacks. Defaults to
22+
// `'DevPortalCustomers'`.
23+
// customersTableName: 'CustomPrefixDevPortalCustomers',
24+
25+
// Change the name of the pre-login accounts table. Useful for multiple stacks. Defaults to
26+
// `'DevPortalPreLoginAccounts'`.
27+
// preLoginAccountsTableName: 'CustomPrefixDevPortalPreLoginAccounts',
28+
29+
// Change the name of the pre-login accounts table. Useful for multiple stacks. Defaults to
30+
// `'DevPortalFeedback'`.
31+
// feedbackTableName: 'CustomPrefixDevPortalFeedback',
32+
33+
// Set this to overwrite-content if you want to reset your custom content back to the defaults.
34+
// Defaults to `''`.
35+
// staticAssetRebuildMode: 'overwrite-content', // ONLY SET
36+
37+
// AWS SAM CLI profile option: optional specific profile from your AWS credential file. Not used
38+
// by default.
39+
// awsSamCliProfile: 'my-profile',
40+
41+
// Set this to `true` if you want to enable development mode. It's `false` by default, and unless
42+
// you're actively developing on the developer portal itself locally, you should generally leave
43+
// it unset as it disables most protections, including CORS.
44+
// developmentMode: false,
45+
}
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// It's recommended you track your live deployments here. You can change this
2+
// any time you want to do a fresh deployment.
3+
// Live: 0
4+
const n = 0
5+
6+
module.exports = {
7+
// Required, bucket must be pre-made
8+
buildAssetsBucket: 'YOUR_LAMBDA_ARTIFACTS_BUCKET_NAME',
9+
10+
// Required, created by stack
11+
stackName: 'dev-portal',
12+
siteAssetsBucket: 'CUSTOM_PREFIX-dev-portal-static-assets',
13+
apiAssetsBucket: 'CUSTOM_PREFIX-dev-portal-artifacts',
14+
15+
// Required, turns on cognito hosted sign in/sign up UI
16+
cognitoDomainName: `YOUR_NAMESPACE-auth${n}`,
17+
18+
// Optional, created by stack
19+
customersTableName: `DevPortalCustomers${n}`,
20+
preLoginAccountsTableName: `DevPortalPreLoginAccounts${n}`,
21+
feedbackTableName: `DevPortalFeedback${n}`,
22+
23+
// optional, created by stack
24+
// It's recommended you set this, though, for easier identification later.
25+
cognitoIdentityPoolName: `DevPortalIdentityPool${n}`,
26+
27+
// Always nuke and rebuild
28+
staticAssetRebuildMode: 'overwrite-content',
29+
30+
// AWS SAM CLI profile option: optional specific profile from your AWS credential file. Not used
31+
// by default.
32+
// awsSamCliProfile: 'my-profile',
33+
34+
// Set this to `true` if you want to enable development mode. It's `false` by default, and unless
35+
// you're actively developing on the developer portal itself locally, you should generally leave
36+
// it unset as it disables most protections, including CORS.
37+
// developmentMode: false,
38+
}
39+
40+
module.exports = {
41+
// required; bucket must be pre-made
42+
buildAssetsBucket: `YOUR_LAMBDA_ARTIFACTS_BUCKET_NAME`,
43+
44+
// required, created by stack
45+
stackName: `YOUR_NAMESPACE-dev-portal${n}`,
46+
siteAssetsBucket: `YOUR_NAMESPACE-dev-portal-static-assets${n}`,
47+
apiAssetsBucket: `YOUR_NAMESPACE-dev-portal-artifacts${n}`,
48+
49+
// optional, created by stack
50+
cognitoDomainName: `YOUR_NAMESPACE-auth${n}`,
51+
customersTableName: `DevPortalCustomers${n}`,
52+
preLoginAccountsTableName: `DevPortalPreLoginAccounts${n}`,
53+
feedbackTableName: `DevPortalFeedback${n}`,
54+
55+
// required; Turns on cognito hosted sign in / sign up UI
56+
cognitoDomainName: `CUSTOM_PREFIX-auth`,
57+
58+
// optional, created by stack
59+
// It's recommended you set this, though, for easier identification later.
60+
cognitoIdentityPoolName: `DevPortalIdentityPool${n}`,
61+
62+
// AWS SAM CLI profile option: optional specific profile from your AWS credential file. Not used
63+
// by default.
64+
// awsSamCliProfile: 'my-profile',
65+
66+
// Always nuke and rebuild
67+
staticAssetRebuildMode: 'overwrite-content',
68+
69+
// Set this to `true` if you want to enable development mode. It's `false` by default, and unless
70+
// you're actively developing on the developer portal itself locally, you should generally leave
71+
// it unset as it disables most CORS protections.
72+
developmentMode: true
73+
}

dev-portal/package.json

+3-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "3.0.2",
44
"private": true,
55
"dependencies": {
6-
"aws-sdk": "^2.326.0",
76
"chart.js": "^2.7.2",
87
"front-matter": "^3.0.0",
98
"jwt-decode": "^2.2.0",
@@ -22,15 +21,11 @@
2221
"yamljs": "^0.3.0"
2322
},
2423
"scripts": {
25-
"get-dependencies": "npm install; npm run build",
2624
"start": "react-scripts start",
27-
"build": "react-scripts build; rm -rf ../lambdas/static-asset-uploader/build; cp -r ./build ../lambdas/static-asset-uploader",
28-
"deploy": "node ./scripts/deploy-stack.js",
29-
"write-config": "node ./scripts/write-config.js",
30-
"release": "npm run build && npm run deploy",
25+
"build": "react-scripts build",
3126
"test": "react-scripts test",
3227
"cover": "react-scripts test --coverage",
33-
"coverage": "cover",
28+
"coverage": "npm run cover",
3429
"eject": "react-scripts eject"
3530
},
3631
"browserslist": [
@@ -45,4 +40,4 @@
4540
"node-fetch": "^2.3.0",
4641
"react-scripts": "^3.4.0"
4742
}
48-
}
43+
}

0 commit comments

Comments
 (0)