@irvingjs/aws-lambda

6.16.0 • Public • Published

AWS Lambda Integration

This package can be used to facilitate the integration of Irving to AWS Lambda.

The @irvingjs/aws-lambda package makes use of the serverless-http package to better integrate to AWS Lambda. We also recommend using the serverless package to deploy to AWS. You can also integrate the deployment to AWS in your CI (process), if desired.

Installation

  1. npm install -g serverless and set it up to connect to AWS properly
  2. You should have the serverless or sls commands available and properly authenticated locally.

Project setup

  1. npm install @irvingjs/aws-lambda
  2. In the root of your Irving project, create an index.js (this file should have the same as the one in your package.json main key) file with the following content:
// index.js

module.exports.irving = require('@irvingjs/core/server');

The irving name exported will be the entry point for your AWS Lambda function to run your Irving site.

  1. You also need to add the aws-lambda to the list of packages in irving.config.server.js. There is no need to add it to the irving.config.js since this is a server configuration:
// irving.config.server.js

const lambdaConfig = require('@irvingjs/aws-lambda');

const config = {
  name: 'irving-dev-app',
  packages: [
    lambdaConfig,
  ],
};

module.exports = config;
  1. In the root of Irving project, create a serverless.yml file with the following content (you can update as needed):
service: irving

provider:
  name: aws
  runtime: nodejs12.x
  region: sa-east-1
  memorySize: 512

functions:
  app:
    handler: index.irving # The same as your index.js exported key.
    events:
      - http:
          path: /
          method: GET
      - http:
          path: /{any+}
          method: GET
  1. When you are ready to deploy your app, npm install --production to remove development dependencies (serverless does this for you but it is a good practice)
  2. And run npm run build to build the app files
  3. Finally, run sls deploy or serverless deploy

Be aware of the 50MB limit for direct upload/deployment from AWS.

Checking AWS Lambda support locally

To test AWS Lambda support locally, we recommend installing the serverless-offline package.Here are the steps if you need to use this package:

  1. Set up your project for AWS Lambda integration.
  2. npm install serverless-offline
  3. Add the serverless-offline plugin to the list:
service: irving

plugins:
  - serverless-offline

...
  1. Finally, run serverless offline or sls offline.

About Large Apps/Sites (Bundle Size)

If you have a really large site/app, your bundle size will probably surpass the AWS Lambda upload limit of 50MB. We are testing with the serverless-webpack to find ways to optimize the bundle as much as possible for size.

More docs about it soon. :)

Readme

Keywords

none

Package Sidebar

Install

npm i @irvingjs/aws-lambda

Weekly Downloads

1

Version

6.16.0

License

MIT

Unpacked Size

33.5 kB

Total Files

7

Last publish

Collaborators

  • alleyops
  • cahdeemer