This package is intended to be used as a Lambda-based Node.js/PHP Job Service using the NYPL PHP Microservice Starter.
This package adheres to PSR-1, PSR-2, and PSR-4 (using the Composer autoloader).
- Node.js >=6.0
- PHP >=7.0
Homebrew is highly recommended for PHP:
brew install php71
brew install php71-redis
- Clone the repo.
- Install required dependencies.
- Run
npm install
to install Node.js packages. - Run
composer install
to install PHP packages. - If you have not already installed
node-lambda
as a global package, runnpm install -g node-lambda
.
- Run
- Setup configuration files.
- Copy the
.env.sample
file to.env
. - Copy
config/var_env.sample
toconfig/var_development.env
.
- Copy the
- Replace sample values in
.env
andconfig/var_development.env
.
Various files are used to configure and deploy the Lambda.
.env
is used locally for two purposes:
- By
node-lambda
for deploying to and configuring Lambda in all environments.- You should use this file to configure the common settings for the Lambda (e.g. timeout, Node version).
- To set local environment variables so the Lambda can be run and tested in a local environment. These parameters are ultimately set by the var environment files when the Lambda is deployed.
Configures npm run
commands for each environment for deployment and testing. Deployment commands may also set
the proper AWS Lambda VPC, security group, and role.
"scripts": {
"deploy-dev": "./node_modules/node-lambda/bin/node-lambda deploy -n JobService -e development -f config/var_development.env -S config/event_sources_dev.json -o arn:aws:iam::224280085904:role/lambda_basic_execution -b subnet-f4fe56af -g sg-1d544067 -P nypl-sandbox",
"deploy-production": "./node_modules/node-lambda/bin/node-lambda deploy -e production -f config/var_production.env -S config/event_sources_production.json -o 'arn:aws:iam::946183545209:role/lambda-full-access' -b subnet-5deecd15,subnet-59bcdd03 -g sg-116eeb60 -P nypl-digital-dev",
"test-create-job": "./node_modules/node-lambda/bin/node-lambda run -f config/var_app -j tests/events/create-job.json -x tests/events/context.json"
},
Configures environment variables common to all environments.
Configures environment variables specific to each environment.
Configures Lambda event sources (triggers) specific to each environment.
To use node-lambda
to process the sample API Gateway event in event.json
, run:
npm run test-create-job
To use the PHP internal web server, run:
php -S localhost:8888 -t . index.php
You can then make a request to the Lambda: http://localhost:8888/api/v0.1/jobs
.
Create a Swagger route to generate Swagger specification documentation:
$service->get("/swagger", function (Request $request, Response $response) {
return SwaggerGenerator::generate(__DIR__ . "/src", $response);
});
Travis CI is configured to run our build and deployment process on AWS.
Our Travis CI/CD pipeline will execute the following steps for each deployment trigger:
- Run unit test coverage
- Build Lambda deployment packages
- Execute the
deploy
hook only fordevelopment
,qa
andmaster
branches to adhere to ournode-lambda
deployment process - Developers do not need to manually deploy the application unless an error occurred via Travis