Commit 7340e686 authored by Vladimir Kiryakov's avatar Vladimir Kiryakov
Browse files

cli scripts

parent 4ed3f1dd
#!/usr/bin/env node
process.env.AWS_SDK_LOAD_CONFIG = 1; // load config from ~/.aws/config
const fs = require('fs');
const AWS = require('aws-sdk');
const prog = require('caporal');
const _ = require('lodash');
const s3 = new AWS.S3();
const cloudformation = new AWS.CloudFormation();
prog
.command('deploy', 'Deploy CloudFormation template to AWS')
// .argument('<stackName>', 'Stack Name', '', 'local')
// .option('--stackName <stackName>', 'Stack Name', 'deviceops-hello-world-frontend')
.option('--stackName <stackName>', 'Stack Name', null, 'deviceops-hello-world-frontend')
.option('--region <region>', 'Stack Name', null, null, false)
.action((args, options) => {
const params = {
StackName: options.stackName,
Parameters: [{
ParameterKey: 'KeyName',
ParameterValue: 'vkiryakov'
}, {
ParameterKey: 'InstanceType',
ParameterValue: 't2.micro'
}],
TemplateBody: fs.readFileSync(`${__dirname}/../aws/cloudformation/template.yaml`, 'utf8')
};
cloudformation.createStack(params, (err, data) => {
if (err) console.error(err, err.stack); // an error occurred
else console.log(JSON.stringify(data)); // successful response
});
});
prog
.command('deploy-web-ui', 'Deploy web UI to s3')
.argument('<bucket>', 'static website bucket')
.action((args, options, logger) => {
});
prog
.command('describe-stacks', 'Deploy CloudFormation template to AWS')
// .argument('<stackName>', 'Stack Name', '', 'local')
// .option('--stackName <stackName>', 'Stack Name', 'deviceops-hello-world-frontend')
.option('--stackName <stackName>', 'Stack Name', null, 'deviceops-hello-world-frontend')
.option('--region <region>', 'Stack Name', null, null, false)
.action((args, options) => {
cloudformation.describeStacks({
StackName: options.stackName
}, (err, data) => {
if (err) {
// console.log(err, err.stack);
return;
}
if (options.region) {
AWS.config.update({region: options.region});
}
const stacks = _.get(data, 'StackSummaries');
console.log(JSON.stringify(data));
})
});
prog.parse(process.argv);
......@@ -3,7 +3,9 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"aws-sdk": "^2.223.1",
"bootstrap": "^4.0.0",
"caporal": "^0.10.0",
"classnames": "^2.2.5",
"history": "^4.7.2",
"lodash": "^4.17.5",
......@@ -33,7 +35,8 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"deploy": "react-scripts build"
},
"devDependencies": {
"stylelint": "^9.2.0",
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment