-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
26 lines (20 loc) · 767 Bytes
/
index.js
File metadata and controls
26 lines (20 loc) · 767 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
const Heroku = require('heroku-client')
const decrypt = require('./decrypt')
const config = require('./dyno-config')
exports.handler = async (ev, context, callback) => {
console.log('Received event: %j', ev)
const { appId, formation } = ev
const appConfig = config[appId] || {}
const updates = appConfig[formation] || appConfig.default
try {
if (!updates) { throw `No config error` }
const token = await decrypt(process.env.HEROKU_API_TOKEN)
const heroku = new Heroku({ token })
const reponse = await heroku.patch(`/apps/${appId}/formation`, { body: { updates } })
console.log(`Updated Formation for ${appId}`, reponse)
context.done()
} catch(err) {
console.error(`Failed to scale ${appId}`, err)
callback(err)
}
}