Skip to content

Commit

Permalink
Merge pull request #265 from danielesalvatore/master
Browse files Browse the repository at this point in the history
Add optional AWS SAM CLI profile option to be used to interact with A…
  • Loading branch information
echo-bravo-yahoo authored Jun 3, 2019
2 parents c172292 + 2c17380 commit 4bf4381
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
3 changes: 3 additions & 0 deletions dev-portal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions dev-portal/scripts/deploy-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 11 additions & 7 deletions dev-portal/scripts/write-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4bf4381

Please sign in to comment.