hapiest-lambda-deploy
v0.0.3
Published
Package that makes deploying AWS Lambda Functions simple and easy
Downloads
10
Readme
Hapiest-lambda-deploy is designed to make it super-simple to deploy one or more lambda functions in a repository.
Setup
Create a deploy config folder with the following files:
i. deployConfig.json (see example below)
{ "lambdaFunctions": [{ "functionName": "hapiestLambdaDeployTest", "zipContents": [ "index.js", "lib" ], "environments": [ { "envName": "env1", "nodeEnvValue": "environment1", "liveAliasName": "LIVE" }, { "envName": "env2", "nodeEnvValue": "environment2", "liveAliasName": "LIVE" } ] }] }
ii. deployCredentials.json (see example below)
{ "awsCredentials": { "accessKeyId": "someIAMAccessKeyId", "secretAccessKey": "someIAMSecretAccessKey", "region": "us-east-1" } }
Create a "bin" .js file similar to the one below
const Promise = require('bluebird'); const Path = require('path'); const NodeConfig = require('config'); const serviceLocator = require('../../services/serviceLocatorFactory').getServiceLocatorSingleton(NodeConfig); const logger = serviceLocator.getLogger(); /** @type {DeployLambdaServiceFactoryFolders} */ const folders = { config: Path.resolve(__dirname, '../config'), projectRoot: Path.resolve(__dirname, '../..') }; const DeployServiceFactory = require('hapiest-lambda-deploy'); const deployService = DeployServiceFactory.create(folders, logger); deployService.deployFromCommandLineArguments(process.argv) .then(() => process.exit()) .catch(err => logger.error('Deploy failed', err));
Update package.json to make it easy to deploy using "npm run ..."
{ "scripts": { "git:ensureClean": "test -z \"$(git status --porcelain)\" || (echo \"Dirty working directory - aborting\" && test -n \"\")", "deploy:env1": "npm run git:ensureClean && node deploy/bin/deploy.js -f hapiestLambdaDeployTest -e env1 -c $(git rev-parse HEAD)" } }
Note, you want to ensure that you have a clean directory so that you don't accidentally deploy code that hasn't been tested / check in. You can optionally remove git:ensureClean step if you like playing Russian Roulette.
Deploy the Lambda function by running
npm run deploy:env1
Running the tests
Currently there's only a single integration test. I plan to add unit tests at some later point in time. To get the integration test up and running, you should:
Create test/helper/integration/config/deployCredentials.json file with valid credentials from Setup step 1
Create an AWS Lambda function with the name
hapiestLambdaDeployTest_env1
and a corresponding alias namedLIVE
Check that the test runs using
npm run test:integration