diff --git a/cloudformation/template.yaml b/cloudformation/template.yaml index b925350a9..551cafc15 100644 --- a/cloudformation/template.yaml +++ b/cloudformation/template.yaml @@ -72,7 +72,7 @@ Parameters: StaticAssetRebuildMode: Type: String - Description: By default, a static asset rebuild doesn't overwrite custom-content. Provide the value `overwrite_content` to replace the custom-content with your local version. Don't do this unless you know what you're doing -- all custom changes in your s3 bucket will be lost. + Description: By default, a static asset rebuild doesn't overwrite custom-content. Provide the value `overwrite-content` to replace the custom-content with your local version. Don't do this unless you know what you're doing -- all custom changes in your s3 bucket will be lost. Default: '' MarketplaceSubscriptionTopicProductCode: diff --git a/dev-portal/README.md b/dev-portal/README.md index bf0191eb8..bb2b58b2f 100644 --- a/dev-portal/README.md +++ b/dev-portal/README.md @@ -30,6 +30,9 @@ module.exports = { // Set this to overwrite-content if you want to reset your custom content back to the defaults. Defaults to `` // staticAssetRebuildMode: `overwrite-content` // ONLY SET + + // AWS SAM CLI profile option: optional specific profile from your AWS credential file. Not used by default + //awsSamCliProfile: "my-profile" } ``` 4. 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 diff --git a/dev-portal/scripts/deploy-stack.js b/dev-portal/scripts/deploy-stack.js index 20155c4e3..90220df84 100644 --- a/dev-portal/scripts/deploy-stack.js +++ b/dev-portal/scripts/deploy-stack.js @@ -21,15 +21,19 @@ const customersTableName = deployerConfig.customersTableName || 'DevPortalCustom const cognitoDomainName = deployerConfig.cognitoDomainName || '' const staticAssetRebuildMode = deployerConfig.staticAssetRebuildMode || '' +// AWS SAM CLI configuration +const awsSamCliProfile = deployerConfig.awsSamCliProfile; +const profileOption = awsSamCliProfile ? `--profile ${awsSamCliProfile}` : '' + function main() { Promise.resolve() - .then(() => execute(`sam package --template-file ${samTemplate} --output-template-file ${packageConfig} --s3-bucket ${buildAssetsBucket}`, true)) - .then(() => execute(`sam deploy --template-file ${packageConfig} --stack-name ${stackName} --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StaticAssetRebuildToken="${Date.now()}" StaticAssetRebuildMode="${staticAssetRebuildMode}" DevPortalSiteS3BucketName="${siteAssetsBucket}" ArtifactsS3BucketName="${apiAssetsBucket}" DevPortalCustomersTableName="${customersTableName}" CognitoDomainNameOrPrefix="${cognitoDomainName}" --s3-bucket ${buildAssetsBucket}`, true)) - .then(() => writeConfig(true)) - .then(() => console.log('\n' + 'Process Complete! Run `npm run start` to launch run the dev portal locally.\n'.green())) - .catch(err => { - console.log(("" + err).red()) - }) + .then(() => execute(`sam package --template-file ${samTemplate} --output-template-file ${packageConfig} --s3-bucket ${buildAssetsBucket} ${profileOption}`, true)) +.then(() => execute(`sam deploy --template-file ${packageConfig} --stack-name ${stackName} --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StaticAssetRebuildToken="${Date.now()}" StaticAssetRebuildMode="${staticAssetRebuildMode}" DevPortalSiteS3BucketName="${siteAssetsBucket}" ArtifactsS3BucketName="${apiAssetsBucket}" DevPortalCustomersTableName="${customersTableName}" CognitoDomainNameOrPrefix="${cognitoDomainName}" --s3-bucket ${buildAssetsBucket} ${profileOption}`, true)) +.then(() => writeConfig(true)) +.then(() => console.log('\n' + 'Process Complete! Run `npm run start` to launch run the dev portal locally.\n'.green())) +.catch(err => { + console.log(("" + err).red()) + }) } if (samTemplate && packageConfig && stackName && buildAssetsBucket && siteAssetsBucket && apiAssetsBucket && customersTableName) { diff --git a/dev-portal/scripts/write-config.js b/dev-portal/scripts/write-config.js index fdc5f90c5..30f2db858 100644 --- a/dev-portal/scripts/write-config.js +++ b/dev-portal/scripts/write-config.js @@ -10,16 +10,20 @@ const { execute, r } = require('./utils.js') const buildConfig = require('../deployer.config.js') const stackName = buildConfig.stackName +// AWS SAM CLI configuration +const awsSamCliProfile = buildConfig.awsSamCliProfile; +const profileOption = awsSamCliProfile ? `--profile ${awsSamCliProfile}` : '' + function writeConfig (swallowOutput) { - return execute(`aws cloudformation describe-stacks --stack-name ${stackName}`, swallowOutput) - .then((result) => { + return execute(`aws cloudformation describe-stacks --stack-name ${stackName} ${profileOption}`, swallowOutput) + .then((result) => { const websiteUrl = (JSON.parse(result.stdout).Stacks[0].Outputs) - .find(output => output.OutputKey === "WebsiteURL").OutputValue + .find(output => output.OutputKey === "WebsiteURL").OutputValue - return fetch(`${websiteUrl}/config.js`).then(response => response.text()) - }) - .then(output => writeFile(r(`../public/config.js`), output)) - .catch(console.error) + return fetch(`${websiteUrl}/config.js`).then(response => response.text()) +}) +.then(output => writeFile(r(`../public/config.js`), output)) +.catch(console.error) } module.exports = writeConfig \ No newline at end of file