forked from amirams/spotinst-functions-examples
-
Notifications
You must be signed in to change notification settings - Fork 16
/
handler.js
35 lines (32 loc) · 950 Bytes
/
handler.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
const rp = require('request-promise')
module.exports.main = function main (event, context, callback) {
let account = process.env['spotAccount']
let token = process.env['spotToken']
let patternId = process.env['spotPattern']
let method = process.env['mathod']
let pattern = process.env['pattern']
let functionId = process.env['spotFunction']
let options = {
uri:'https://api.spotinst.io/functions/pattern/'+patternId,
method:'PUT' ,
qs:{accountId:account},
headers:{
"Content-Type": "application/json",
"Authorization": "Bearer " + token},
body:{
"pattern": {
"method": method,
"pattern": pattern,
"functionId": functionId
}
},
json:true
}
rp(options).then((res)=>{
console.log(res['response'])
callback(null, {statusCode: 200, body: "Success"});
}).catch((err)=>{
console.log(err)
callback(null, {statusCode: 400, body: "Error Check Logs"});
})
};