Skip to content

Commit 9a5ba4b

Browse files
author
amazon-meaisiah
authored
Merge pull request awslabs#378 from awslabs/dev-tweaks
Tweak the dev setup a little
2 parents b630a3b + 2c30760 commit 9a5ba4b

File tree

3 files changed

+93
-80
lines changed

3 files changed

+93
-80
lines changed

dev-portal/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ Note: this is for advanced users who want to modify the developer portal code it
66

77
1. Make sure you have [Node](https://nodejs.org/en/download/) installed - the setup process assumes you have at least Node v11, but v12 is recommended.
88

9-
1. Make sure you have the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) and the [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) installed - these are required for `npm run deploy` to work.
9+
2. Make sure you have the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) and the [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) installed - these are required for `npm run deploy` to work.
1010

11-
2. Navigate to the `/dev-portal/` folder, and run `npm install`
11+
3. Navigate to the `/dev-portal/` folder, and run `npm install`
1212

13-
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)
13+
4. 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)
1414

15-
4. Create a `deployer.config.js` file inside `/dev-portal/` with the structure below. We recommend using the same values you used during the initial deployment. (You can put this elsewhere and pass `DEPLOYER_CONFIG=/path/to/deployer.config.js` as an environment variable, in case you would prefer to manage it outside the repo.)
15+
5. Create a `deployer.config.js` file inside `/dev-portal/` with the structure below. We recommend using the same values you used during the initial deployment. (You can put this elsewhere and pass `DEPLOYER_CONFIG=/path/to/deployer.config.js` as an environment variable, in case you would prefer to manage it outside the repo.)
1616

1717
```js
1818
// replace your-lambda-artifacts-bucket-name with the name of the bucket you created in step 1
@@ -106,13 +106,13 @@ Note: this is for advanced users who want to modify the developer portal code it
106106
}
107107
```
108108

109-
5. Run `npm run release`. This will build the static assets, deploy them, and generate the `dev-portal/public/config.js` file needed for local development. Take note of the bucket names you use.
109+
6. Run `npm run release`. This will build the static assets, deploy them, and generate the `dev-portal/public/config.js` file needed for local development. Take note of the bucket names you use.
110110

111-
6. Run `npm run start` to start the local development server at `localhost:3000`.
111+
7. Run `npm run start` to start the local development server at `localhost:3000`.
112112

113-
7. If you created the stack for the first time, 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`).
113+
8. If you created the stack for the first time, 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`).
114114

115-
7. Make changes locally, test them at `localhost:3000`, and, when satisfied, run `npm run release` to build and upload the changes to your cloud dev portal.
115+
9. Make changes locally, test them at `localhost:3000`, and, when satisfied, run `npm run release` to build and upload the changes to your cloud dev portal.
116116

117117
### npm Scripts
118118

dev-portal/scripts/deploy-stack.js

Lines changed: 15 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,80 +2,23 @@
22
// SPDX-License-Identifier: Apache-2.0
33
'use strict'
44

5-
const { execute, r, red, green } = require('./utils.js')
5+
const { red, green } = require('./utils.js')
66

77
const deployerConfig = require('./get-deployer-config.js')
88
const writeConfig = require('./write-config.js')
9-
10-
const errors = []
11-
12-
function getRequired (key) {
13-
const value = deployerConfig[key]
14-
if (value) return value
15-
errors.push(key + ' must be defined')
16-
}
17-
18-
function getOptional (key, orElse) {
19-
return deployerConfig[key] || orElse
9+
const deployTemplate = require('./deploy-template.js')
10+
11+
async function main() {
12+
const missing = deployTemplate(deployerConfig)
13+
14+
if (missing != null) {
15+
for (const key of missing) console.error(red(key + ' must be defined'))
16+
} else {
17+
await writeConfig()
18+
console.log()
19+
console.log(green('Process Complete! Run `npm run start` to launch run the dev portal locally.'))
20+
console.log()
21+
}
2022
}
2123

22-
// required inputs
23-
const stackName = getRequired('stackName')
24-
const buildAssetsBucket = getRequired('buildAssetsBucket')
25-
const siteAssetsBucket = getRequired('siteAssetsBucket')
26-
const apiAssetsBucket = getRequired('apiAssetsBucket')
27-
const cognitoDomainName = getRequired('cognitoDomainName')
28-
29-
// required (and defaulted) inputs
30-
const samTemplate = getOptional('samTemplate', r('../../cloudformation/template.yaml'))
31-
const packageConfig = getOptional('packageConfig', r('../../cloudformation/packaged.yaml'))
32-
const customersTableName = getOptional('customersTableName')
33-
const preLoginAccountsTableName = getOptional('preLoginAccountsTableName')
34-
const feedbackTableName = getOptional('feedbackTableName')
35-
const cognitoIdentityPoolName = getOptional('cognitoIdentityPoolName')
36-
37-
// optional inputs
38-
const staticAssetRebuildMode = getOptional('staticAssetRebuildMode', '')
39-
const developmentMode = getOptional('developmentMode')
40-
41-
// AWS SAM CLI configuration
42-
const awsSamCliProfile = getOptional('awsSamCliProfile')
43-
44-
async function main () {
45-
execute('sam', [
46-
'package',
47-
'--template-file', samTemplate,
48-
'--output-template-file', packageConfig,
49-
'--s3-bucket', buildAssetsBucket,
50-
...(awsSamCliProfile ? ['--profile', awsSamCliProfile] : [])
51-
])
52-
execute('sam', [
53-
'deploy',
54-
'--template-file', packageConfig,
55-
'--stack-name', stackName,
56-
'--capabilities', 'CAPABILITY_NAMED_IAM',
57-
'--parameter-overrides',
58-
`StaticAssetRebuildToken=${Date.now()}`,
59-
...(staticAssetRebuildMode ? [`StaticAssetRebuildMode=${staticAssetRebuildMode}`] : []),
60-
`DevPortalSiteS3BucketName=${siteAssetsBucket}`,
61-
`ArtifactsS3BucketName=${apiAssetsBucket}`,
62-
...(customersTableName ? [`DevPortalCustomersTableName=${customersTableName}`] : []),
63-
...(preLoginAccountsTableName ? [`DevPortalPreLoginAccountsTableName=${preLoginAccountsTableName}`] : []),
64-
...(feedbackTableName ? [`DevPortalFeedbackTableName=${feedbackTableName}`] : []),
65-
...(cognitoIdentityPoolName ? [`CognitoIdentityPoolName=${cognitoIdentityPoolName}`] : []),
66-
...(developmentMode ? [`LocalDevelopmentMode=${developmentMode}`] : []),
67-
`CognitoDomainNameOrPrefix=${cognitoDomainName}`,
68-
'--s3-bucket', buildAssetsBucket,
69-
...(awsSamCliProfile ? ['--profile', awsSamCliProfile] : [])
70-
])
71-
await writeConfig()
72-
console.log()
73-
console.log(green('Process Complete! Run `npm run start` to launch run the dev portal locally.'))
74-
console.log()
75-
}
76-
77-
if (errors.length) {
78-
for (const error of errors) console.error(red(error))
79-
} else {
80-
main().catch(err => console.error(red(err)))
81-
}
24+
main().catch(err => console.error(red(err)))

dev-portal/scripts/deploy-template.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
'use strict'
4+
5+
const { execute, r } = require('./utils.js')
6+
7+
module.exports = deployerConfig => {
8+
const missing = []
9+
10+
function getRequired(key) {
11+
const value = deployerConfig[key]
12+
if (value) return value
13+
missing.push(key)
14+
}
15+
16+
function getOptional(key, orElse) {
17+
return deployerConfig[key] || orElse
18+
}
19+
20+
// required inputs
21+
const stackName = getRequired('stackName')
22+
const buildAssetsBucket = getRequired('buildAssetsBucket')
23+
const siteAssetsBucket = getRequired('siteAssetsBucket')
24+
const apiAssetsBucket = getRequired('apiAssetsBucket')
25+
const cognitoDomainName = getRequired('cognitoDomainName')
26+
27+
// required (and defaulted) inputs
28+
const samTemplate = getOptional('samTemplate', r('../../cloudformation/template.yaml'))
29+
const packageConfig = getOptional('packageConfig', r('../../cloudformation/packaged.yaml'))
30+
const customersTableName = getOptional('customersTableName')
31+
const preLoginAccountsTableName = getOptional('preLoginAccountsTableName')
32+
const feedbackTableName = getOptional('feedbackTableName')
33+
const cognitoIdentityPoolName = getOptional('cognitoIdentityPoolName')
34+
35+
// optional inputs
36+
const staticAssetRebuildMode = getOptional('staticAssetRebuildMode', '')
37+
const developmentMode = getOptional('developmentMode')
38+
39+
// AWS SAM CLI configuration
40+
const awsSamCliProfile = getOptional('awsSamCliProfile')
41+
42+
if (missing.length) return missing
43+
44+
execute('sam', [
45+
'package',
46+
'--template-file', samTemplate,
47+
'--output-template-file', packageConfig,
48+
'--s3-bucket', buildAssetsBucket,
49+
...(awsSamCliProfile ? ['--profile', awsSamCliProfile] : [])
50+
])
51+
execute('sam', [
52+
'deploy',
53+
'--template-file', packageConfig,
54+
'--stack-name', stackName,
55+
'--capabilities', 'CAPABILITY_NAMED_IAM',
56+
'--parameter-overrides',
57+
`StaticAssetRebuildToken=${Date.now()}`,
58+
...(staticAssetRebuildMode ? [`StaticAssetRebuildMode=${staticAssetRebuildMode}`] : []),
59+
`DevPortalSiteS3BucketName=${siteAssetsBucket}`,
60+
`ArtifactsS3BucketName=${apiAssetsBucket}`,
61+
...(customersTableName ? [`DevPortalCustomersTableName=${customersTableName}`] : []),
62+
...(preLoginAccountsTableName ? [`DevPortalPreLoginAccountsTableName=${preLoginAccountsTableName}`] : []),
63+
...(feedbackTableName ? [`DevPortalFeedbackTableName=${feedbackTableName}`] : []),
64+
...(cognitoIdentityPoolName ? [`CognitoIdentityPoolName=${cognitoIdentityPoolName}`] : []),
65+
...(developmentMode ? [`LocalDevelopmentMode=${developmentMode}`] : []),
66+
`CognitoDomainNameOrPrefix=${cognitoDomainName}`,
67+
'--s3-bucket', buildAssetsBucket,
68+
...(awsSamCliProfile ? ['--profile', awsSamCliProfile] : [])
69+
])
70+
}

0 commit comments

Comments
 (0)