forked from jeffnoehren/spotinst-function-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (42 loc) · 1022 Bytes
/
index.js
File metadata and controls
45 lines (42 loc) · 1022 Bytes
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
39
40
41
42
43
44
45
const rp = require('request-promise')
module.exports.main = function main (event, context, callback) {
let account = process.env['spotAccount']
let token = process.env['spotToken']
let group = process.env['spotGroup']
let target = process.env['target']
let max = process.env['max']
let min = process.env['min']
let options = {
uri:'https://api.spotinst.io/aws/ec2/group/'+group,
method: "PUT",
qs: {accountId: account},
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + token},
body:{
"group": {
"capacity": {
"target": target,
"minimum": min,
"maximum": max
}
}
},
json:true
}
rp(options).then((res)=>{
console.log(res)
callback(null, {
statusCode: 200,
body: 'Success: Adjustment Accepted',
headers: {"Content-Type": "application/json"}
});
}).catch((err)=>{
console.log(err)
callback(null, {
statusCode: 400,
body: 'Error: Check Logs',
headers: {"Content-Type": "application/json"}
});
})
};