-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathremove-environment.js
More file actions
28 lines (24 loc) · 969 Bytes
/
remove-environment.js
File metadata and controls
28 lines (24 loc) · 969 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
import Promise from 'bluebird'
import merge from 'lodash.merge'
import { getFunction, updateFunction } from './aws/lambda'
import { lambdaConfig, funcs } from './load'
import { AWSEnvironmentVariableNotFound } from './errors'
const pattern = '*'
export default async function (env, vars) {
const configs = await Promise.map(funcs(pattern), async (name) => { return { name, config: await lambdaConfig(name, env) } })
return Promise.map(configs, async ({ name, config }) => {
const oldFunc = await getFunction({ FunctionName: config.FunctionName, Qualifier: env })
const wantedFunc = merge({}, oldFunc)
return updateFunction(oldFunc, deleteEnvVars(wantedFunc, vars))
}, { concurrency: 1 })
}
function deleteEnvVars (func, envVars) {
envVars.forEach((envVar) => {
try {
delete func.Config.Environment.Variables[envVar]
} catch (e) {
throw new AWSEnvironmentVariableNotFound(func.FunctionName, envVar)
}
})
return func
}