forked from jeffnoehren/spotinst-function-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
38 lines (35 loc) · 1.05 KB
/
handler.js
File metadata and controls
38 lines (35 loc) · 1.05 KB
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
37
38
/*
This function will unsuspend one of your Elastigroups policy. All you need is to enter
in your account ID, Spotinst token, group name and policy name. You can also set this
function on a timer so it will automatically unsuspend a policy on a regualr interval.
*/
var rp = require('request-promise');
module.exports.main = function main (event, context, callback) {
let token = process.env['spotToken']
let account = process.env['spotAccount']
let group = process.env['spotGroup']
let policyName = process.env['spotPolicy']
let options = {
uri:'https://api.spotinst.io/aws/ec2/group/' + group + '/scale/resumePolicy',
method: 'POST',
qs: {accountId: account,
policyName: policyName},
headers:{
"Content-Type": "application/json",
"Authorization": "Bearer " + token},
json:true
}
rp(options).then((response)=>{
console.log(response)
callback(null, {
statusCode: 200,
body: "Success"
});
}).catch((err)=>{
console.log(err)
callback(null, {
statusCode: 400,
body: "Error, check logs for more details"
});
})
};