-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (34 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var aws = require('aws-sdk');
var opsWorks = new aws.OpsWorks({ apiVersion: 'latest', region: 'us-east-1' });
exports.handler = function(event, context) {
var deploy = false;
var mainBranch = "master";
if (event && event.pullrequest && event.pullrequest.destination.branch.name == mainBranch) {
deploy = true;
}
if (event &&
event.push &&
event.push.changes[0].new.name == mainBranch ||
/*event.repository.full_name == "vedor/repo-name" Deploy only desired repository*/) {
deploy = true;
}
if (deploy) {
var params = {
Command: {
Name: 'deploy',
},
StackId: STRING,
AppId: STRING,
Comment: 'Deploying from lambda' /* Custom user comment showed in deployments interface */
};
opsWorks.createDeployment(params, function(err, data) {
if (err) {
console.log(err, err.stack);
context.fail(err);
}
else {
context.succeed(data);
}
});
}
};