Commit 785ad20b authored by Vladimir Kiryakov's avatar Vladimir Kiryakov
Browse files

validate region params

parent e386b0d6
......@@ -8,10 +8,12 @@ yarn install
yarn run deploy --key <Name of an existing EC2 KeyPair>
```
- wait for CloudFormation Stack creation
```bash
yarn run publish
```
- to see deploy information execute
```bash
yarn run describe-stacks
```
......
......@@ -19,8 +19,6 @@ Mappings:
AMI: ami-916f59f4
us-west-1:
AMI: ami-925144f2
eu-west-2:
AMI: ami-4e79ed36
Resources:
S3Bucket:
Type: AWS::S3::Bucket
......
......@@ -5,22 +5,21 @@ const prog = require('caporal');
const {
describeStacks, createOrUpdateStack, changeRegion, syncUI, deleteStack,
DEFAULT_INSTANCE_TYPE, DEFAULT_STACK_NAME
DEFAULT_INSTANCE_TYPE, DEFAULT_STACK_NAME, DEFAULT_REGION
} = require('./s3-service');
const NO_VALIDATE = null;
const REGION_VALIDATE = ['us-east-1', 'us-east-2', 'us-west-1']; //RegionMap in CloudFormation template
prog
.command('deploy', 'Deploy CloudFormation template to AWS')
.option('--stackName <stackName>', 'Stack Name', NO_VALIDATE, DEFAULT_STACK_NAME)
.option('--region <region>', 'AWS region', NO_VALIDATE, null, false)
.option('--region <region>', 'AWS region', REGION_VALIDATE, DEFAULT_REGION, false)
.option('--key <key>', 'Name of an existing EC2 KeyPair to enable SSH access to the instances', NO_VALIDATE, null, true)
.option('--instanceType <instanceType>', 'EC2 Instance Type', NO_VALIDATE, DEFAULT_INSTANCE_TYPE, false)
.action((args, options) => {
if (options.region) {
changeRegion(options.region);
}
changeRegion(options.region);
createOrUpdateStack({
stackName: options.stackName,
......@@ -52,12 +51,10 @@ prog
prog
.command('describe-stacks', 'Deploy CloudFormation template to AWS')
.option('--stackName <stackName>', 'Stack Name', NO_VALIDATE, DEFAULT_STACK_NAME)
.option('--region <region>', 'AWS region', NO_VALIDATE, null, false)
.option('--region <region>', 'AWS region', NO_VALIDATE, DEFAULT_REGION, false)
.action((args, options) => {
if (options.region) {
changeRegion(options.region);
}
changeRegion(options.region);
describeStacks(options.stackName)
.then((data) => {
......@@ -71,12 +68,10 @@ prog
prog
.command('delete', 'Delete CloudFormation template')
.option('--stackName <stackName>', 'Stack Name', NO_VALIDATE, DEFAULT_STACK_NAME)
.option('--region <region>', 'AWS region', NO_VALIDATE, null, false)
.option('--region <region>', 'AWS region', REGION_VALIDATE, DEFAULT_REGION, false)
.action((args, options) => {
if (options.region) {
changeRegion(options.region);
}
changeRegion(options.region);
deleteStack(options.stackName)
.then((data) => {
......
/* global Promise */
process.env.AWS_SDK_LOAD_CONFIG = 1; // load config from ~/.aws/config
const fs = require('fs');
const {exec} = require('child_process');
const AWS = require('aws-sdk');
const _ = require('lodash');
const s3 = new AWS.S3();
const cloudformation = new AWS.CloudFormation();
const DEFAULT_STACK_NAME = 'deviceops-hello-world-frontend';
const DEFAULT_INSTANCE_TYPE = 't2.micro';
const DEFAULT_REGION = 'us-east-1';
let cloudformation = new AWS.CloudFormation({region: DEFAULT_REGION});
const changeRegion = (region) => {
return AWS.config.update({region});
cloudformation = new AWS.CloudFormation({region})
};
const describeStacks = (stackName) => {
......@@ -131,6 +131,7 @@ const deleteStack = (stackName) => {
module.exports = {
DEFAULT_STACK_NAME,
DEFAULT_INSTANCE_TYPE,
DEFAULT_REGION,
changeRegion,
describeStacks,
syncUI,
......
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