Skip to content

Commit

Permalink
🎉 Extend "--env-from-file" support to update command
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Feb 14, 2018
1 parent f8c0083 commit 8eb6a3c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ async function main () {

const updateList = new Listr([
tasks.packageApp,
tasks.readEnvironmentFile,
tasks.updateLambdaEnvironment,
tasks.updateLambdaFunction,
tasks.loadSwaggerDefinition,
tasks.generateSwaggerDefinition,
Expand Down
9 changes: 9 additions & 0 deletions lib/amazon.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ exports.getFunctionEnvironment = function ({ functionName }) {
return lambda.getFunctionConfiguration(params).promise().then(res => (res.Environment && res.Environment.Variables) || {})
}

exports.updateFunctionEnvironment = function ({ functionName, environment }) {
const params = {
FunctionName: functionName,
Environment: { Variables: environment }
}

return lambda.updateFunctionConfiguration(params).promise().then(res => res.FunctionArn)
}

exports.createApiGateway = async function ({ definition, lambdaArn }) {
const params = {
body: JSON.stringify(definition),
Expand Down
9 changes: 9 additions & 0 deletions lib/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ exports.updateLambdaFunction = {
}
}

exports.updateLambdaEnvironment = {
title: 'Update Lambda environment',
enabled: (ctx) => Boolean(ctx.args['--env-from-file']),
task: async (ctx, task) => {
await amazon.updateFunctionEnvironment({ functionName: ctx.args['<name>'], environment: ctx.environment })
task.title = `Updated existing Lambda environment`
}
}

exports.loadSwaggerDefinition = {
title: 'Load Swagger definition',
enabled: (ctx) => Boolean(ctx.args['--swagger']),
Expand Down

0 comments on commit 8eb6a3c

Please sign in to comment.