lambda-lambda-lambda
Advanced tools
+1
-1
| { | ||
| "name": "lambda-lambda-lambda", | ||
| "description": "AWS Lambda@Edge serverless application router.", | ||
| "version": "0.3.1", | ||
| "version": "0.3.2", | ||
| "main": "src/Router.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
+35
-105
@@ -22,2 +22,11 @@ # lambda-lambda-lambda | ||
| ## Getting started | ||
| The easiest way to build a new application, without the need to [manually install](#installation) this package, is to use the [Lambda Lambda Lambda VS Code extension](https://marketplace.visualstudio.com/items?itemName=Nuxy.vscode-lambda-lambda-lambda) which allows you to: | ||
| - Scaffold app sources and dependencies. | ||
| - Run it locally (in [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)) | ||
| - Test code changes in realtime. | ||
| - Deploy app sources to AWS. | ||
| ## Installation | ||
@@ -31,8 +40,6 @@ | ||
| ### Lambda function | ||
| Unless your application requires [complex routing](#complex-routing), route handlers can be defined within the [Lambda function scope](https://docs.aws.amazon.com/lambda/latest/operatorguide/global-scope.html). Otherwise [route handlers](#route-handler) are loaded from `appName/src/routes` directory in hierarchical order, starting with the default handler `appName/src/app.js` as described below. | ||
| Unless your application requires [complex routing](#complex-routing), route handlers can be defined within the [Lambda function scope](https://docs.aws.amazon.com/lambda/latest/operatorguide/global-scope.html). | ||
| ```javascript | ||
| // .. sam-app/src/app.js | ||
| // .. appName/src/app.js | ||
@@ -76,9 +83,7 @@ 'use strict'; | ||
| ### Common methods | ||
| ## Common methods | ||
| The following methods are supported based on the class context. For further information please refer to the [JSDoc generated documentation](#cli-options) which includes method `arguments`/`return` types and general usage examples. | ||
| #### Router | ||
| | Method | Description | | ||
| | Router Method | Description | | ||
| |-----------------------------|-------------------------------------------| | ||
@@ -95,5 +100,3 @@ | `router.setPrefix(path)` | Set URI path prefix. | | ||
| #### router/Request | ||
| | Method | Description | | ||
| | Request Method | Description | | ||
| |---------------------|---------------------------------------------------| | ||
@@ -110,5 +113,3 @@ | `req.is(mimeType)` | Check `Accept` matches the given value. | | ||
| #### router/Response | ||
| | Method | Description | | ||
| | Response Method | Description | | ||
| |---------------------------------|---------------------------------| | ||
@@ -121,3 +122,3 @@ | `res.setHeader(name, value)` | Set HTTP response header. | | ||
| ### Complex routing | ||
| ## Complex routing | ||
@@ -134,6 +135,6 @@ When constructing a routing handler the following methods/aliases are supported. While they can be used interchangeably they must define either a [Route](#route-handler) or [Resource](#resource-handler) handler, but not both. | ||
| #### Route handler | ||
| ### Route handler | ||
| ```javascript | ||
| // .. sam-app/src/routes/foo.js | ||
| // .. appName/src/routes/foo.js | ||
@@ -188,6 +189,6 @@ 'use strict'; | ||
| #### Resource handler | ||
| ### Resource handler | ||
| ```javascript | ||
| // .. sam-app/src/routes/foo/bar.js | ||
| // .. appName/src/routes/foo/bar.js | ||
@@ -217,30 +218,10 @@ 'use strict'; | ||
| /** | ||
| * PATCH /api/foo/bar/<resourceId> | ||
| */ | ||
| patch (req, res, id) { | ||
| res.status(204).send(); | ||
| }, | ||
| /** | ||
| * DELETE /api/foo/bar/<resourceId> | ||
| */ | ||
| delete (req, res, id) { | ||
| res.status(410).send(); | ||
| }, | ||
| /** | ||
| * POST /api/foo/bar/<resourceId> | ||
| */ | ||
| post (req, res, id) { | ||
| res.status(200).send(); | ||
| } | ||
| .. | ||
| }; | ||
| ``` | ||
| #### Mixed Route/Resource handler | ||
| ### Mixed Route/Resource handler | ||
| ```javascript | ||
| // .. sam-app/src/routes/foo.js | ||
| // .. appName/src/routes/foo.js | ||
@@ -253,3 +234,3 @@ 'use strict'; | ||
| module.exports = { | ||
| resource: ['get', 'put', 'patch', 'submit'], | ||
| resource: ['put'], | ||
@@ -265,3 +246,3 @@ /** | ||
| /** | ||
| * GET /api/foo/<resourceId> | ||
| * PUT /api/foo/<resourceId> | ||
| */ | ||
@@ -273,52 +254,12 @@ get (req, res, id) { | ||
| /** | ||
| * PUT /api/foo | ||
| */ | ||
| create (req, res) { | ||
| res.status(201).send(); | ||
| }, | ||
| /** | ||
| * PUT /api/foo/<resourceId> | ||
| */ | ||
| put (req, res, id) { | ||
| res.status(201).send(); | ||
| }, | ||
| /** | ||
| * PATCH /api/foo | ||
| */ | ||
| update (req, res) { | ||
| res.status(204).send(); | ||
| }, | ||
| /** | ||
| * PATCH /api/foo/<resourceId> | ||
| */ | ||
| patch (req, res, id) { | ||
| res.status(204).send(); | ||
| }, | ||
| /** | ||
| * DELETE /api/foo | ||
| */ | ||
| delete (req, res) { | ||
| res.status(410).send(); | ||
| }, | ||
| /** | ||
| * POST /api/foo/<resourceId> | ||
| */ | ||
| submit (req, res, id) { | ||
| res.status(200).send(); | ||
| } | ||
| .. | ||
| }; | ||
| ``` | ||
| ### Middleware | ||
| ## Middleware | ||
| #### Content-Type | ||
| ### Content-Type | ||
| ```javascript | ||
| // .. sam-app/src/middleware/ContentTypeHeader.js | ||
| // .. appName/src/middleware/ContentTypeHeader.js | ||
@@ -337,6 +278,6 @@ 'use strict'; | ||
| #### Access-Control | ||
| ### Access-Control | ||
| ```javascript | ||
| // .. sam-app/src/middleware/AccessControlHeaders.js | ||
| // .. appName/src/middleware/AccessControlHeaders.js | ||
@@ -367,6 +308,6 @@ 'use strict'; | ||
| #### Basic Authentication | ||
| ### Basic Authentication | ||
| ```javascript | ||
| // .. sam-app/src/middleware/BasicAuthHandler.js | ||
| // .. appName/src/middleware/BasicAuthHandler.js | ||
@@ -392,18 +333,7 @@ 'use strict'; | ||
| ## App Example | ||
| ## AWS requirements | ||
| A [restfulAPI](https://github.com/nuxy/lambda-lambda-lambda/tree/master/example) has been provided with this package that can either be run locally in a [Docker container](https://code.visualstudio.com/docs/remote/containers) or deployed to [Lambda@Edge using SAM](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-deploy.html). | ||
| In order to successfully deploy your application you must have [set-up your AWS Config](https://docs.aws.amazon.com/config/latest/developerguide/gs-cli.html) and have [created an IAM user](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html) with the following [policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage.html): | ||
| ### Running in Docker | ||
| When launching [VS Code](https://code.visualstudio.com) you will be prompted to "Open as Container". Once launched, the application can be accessed at: http://localhost:3000/api/example | ||
| ### Deploying to AWS | ||
| $ cd example & ./deploy | ||
| In order to successfully deploy you must have [set-up your AWS Config](https://docs.aws.amazon.com/config/latest/developerguide/gs-cli.html) and have [created an IAM user](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html) with the following [policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage.html): | ||
| - [IAMFullAccess](https://console.aws.amazon.com/iam/home#/policies/arn%3Aaws%3Aiam%3A%3Aaws%3Apolicy%2FIAMFullAccess) | ||
| - [AmazonS3FullAccess](https://console.aws.amazon.com/iam/home#/policies/arn%3Aaws%3Aiam%3A%3Aaws%3Apolicy%2FAmazonS3FullAccess) | ||
| - [CloudFrontFullAccess](https://console.aws.amazon.com/iam/home#/policies/arn%3Aaws%3Aiam%3A%3Aaws%3Apolicy%2FCloudFrontFullAccess) | ||
@@ -410,0 +340,0 @@ - [AWSCloudFormationFullAccess](https://console.aws.amazon.com/iam/home#/policies/arn%3Aaws%3Aiam%3A%3Aaws%3Apolicy%2FAWSCloudFormationFullAccess) |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
35382
-2.83%375
-15.73%