@irvingjs/aws-lambda
v6.16.0
Published
Run Irving on AWS Lambda
Downloads
158
Readme
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
npm install -g serverless
and set it up to connect to AWS properly- You should have the
serverless
orsls
commands available and properly authenticated locally.
Project setup
npm install @irvingjs/aws-lambda
- In the root of your Irving project, create an
index.js
(this file should have the same as the one in yourpackage.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.
- You also need to add the
aws-lambda
to the list of packages inirving.config.server.js
. There is no need to add it to theirving.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;
- 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
- 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) - And run
npm run build
to build the app files - Finally, run
sls deploy
orserverless 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:
- Set up your project for AWS Lambda integration.
npm install serverless-offline
- Add the
serverless-offline
plugin to the list:
service: irving
plugins:
- serverless-offline
...
- Finally, run
serverless offline
orsls 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. :)