forked from amirams/spotinst-functions-examples
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathhandler.js
More file actions
42 lines (39 loc) · 1.14 KB
/
handler.js
File metadata and controls
42 lines (39 loc) · 1.14 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
39
40
41
42
const rp = require('request-promise')
/*
This funciton will scale down your EMR Elastigroup by whatever adjustment that
you set in the ajustment variable. It will never go below zero and will return
with a status 400 if you try. To get this function to work input your Spotinst
credentials below.
*/
module.exports.main = function main (event, context, callback) {
// Spotist credentials
let account = process.env['spotAccount']
let token = process.env['spotToken']
let emr = process.env['spotEMR']
let adjustment = process.env['adjustment']
let options = {
uri:'https://api.spotinst.io/aws/emr/mrScaler/'+emr+'/scale/down',
method: "PUT",
qs: {accountId: account,
adjustment: adjustment},
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + token},
json:true
}
rp(options).then((res)=>{
console.log(res)
callback(null, {
statusCode: 200,
body: 'Success: Scaled Down',
headers: {"Content-Type": "application/json"}
});
}).catch((err)=>{
console.log(err)
callback(null, {
statusCode: 400,
body: 'Error: Check Logs',
headers: {"Content-Type": "application/json"}
});
})
};