Comparing version 0.0.3-beta-1 to 0.0.3-beta-2
{ | ||
"name": "kes", | ||
"version": "0.0.3-beta-1", | ||
"version": "0.0.3-beta-2", | ||
"description": "Making deployment to AWS using CloudFormation easier and fun", | ||
@@ -5,0 +5,0 @@ "scripts": {}, |
@@ -46,2 +46,10 @@ 'use strict'; | ||
uploadToS3(bucket, key, body, cb) { | ||
const s3 = new AWS.S3(); | ||
s3.upload({ Bucket: bucket, Key: key, Body: body }, (e, r) => { | ||
console.log(`Uploaded document to s3://${r.Bucket}/${r.key}`); | ||
cb(e, r); | ||
}); | ||
} | ||
/** | ||
@@ -67,11 +75,8 @@ * Uploads the Cloud Formation template to a given S3 location | ||
// upload CF template to S3 | ||
const s3 = new AWS.S3(); | ||
s3.upload({ | ||
Bucket: parsed[1], | ||
Key: `${parsed[2]}/cloudformation.yml`, | ||
Body: fs.readFileSync('.kes/cloudformation.yml') | ||
}, (e, r) => { | ||
console.log(`Uploaded CF template to s3://${r.Bucket}/${r.key}`); | ||
cb(e, r); | ||
}); | ||
this.uploadToS3( | ||
parsed[1], | ||
`${parsed[2]}/cloudformation.yml`, | ||
fs.readFileSync('.kes/cloudformation.yml'), | ||
cb | ||
); | ||
} | ||
@@ -82,5 +87,9 @@ | ||
const name = this.stage ? `${stackName}-${this.stage}` : stackName; | ||
// Run the cloudformation cli command | ||
const cf = new AWS.CloudFormation(); | ||
cf.updateStack({ | ||
let opFn = op === 'create' ? cf.createStack : cf.updateStack; | ||
const wait = op === 'create' ? 'stackCreateComplete' : 'stackUpdateComplete'; | ||
opFn = opFn.bind(cf); | ||
opFn({ | ||
StackName: name, | ||
@@ -105,3 +114,3 @@ TemplateURL: templateUrl, | ||
else { | ||
console.log('There was an error updating the CF stack'); | ||
console.log('There was an error creating/updating the CF stack'); | ||
return cb(e); | ||
@@ -112,5 +121,13 @@ } | ||
console.log('Waiting for the CF operation to complete'); | ||
cf.waitFor('stackUpdateComplete', { StackName: name }, (e, r) => { | ||
console.log('CF update is completed'); | ||
cb(e, r); | ||
cf.waitFor(wait, { StackName: name }, (e, r) => { | ||
if (e) { | ||
if (e.message.includes('Resource is not in the state')) { | ||
console.log('CF create/update failed. Check the logs'); | ||
} | ||
return cb(e); | ||
} | ||
else { | ||
console.log(`CF operation is in state of ${r.Stacks[0].StackStatus}`); | ||
cb(null, r); | ||
} | ||
}); | ||
@@ -117,0 +134,0 @@ } |
@@ -9,3 +9,2 @@ 'use strict'; | ||
const exec = require('./common').exec; | ||
const getProfile = require('./common').getProfile; | ||
@@ -105,3 +104,3 @@ function getLambdaZipFile(handler) { | ||
Bucket: parsed[1], | ||
Key: `${parsed[2]}/${folderName}.zip`, | ||
Key: `${parsed[2]}/lambda/${folderName}.zip`, | ||
Body: fs.readFileSync(`./build/lambda/${folderName}.zip`) | ||
@@ -108,0 +107,0 @@ }).promise(); |
43022
1163