@serverless/mono

 

Usage no npm install needed!

<script type="module">
  import serverlessMono from 'https://cdn.skypack.dev/@serverless/mono';
</script>

README

https://www.serverless.com

mono

 

Easily host web frameworks and applications on a single AWS Lambda function using this Serverless Component.

Features

  • Designed to make it easy to host pre-existing web frameworks (e.g. Express.js, Hapi) or any large web application on a single AWS Lambda Function.
  • Blazing Fast Uploads via AWS S3 Accelerated Transfer and Multi-Part.
  • Dependencies are automatically put in AWS Lambda Layers, reducing cold-start time and further reducing upload time.
  • Simple shim for receiving and responding to HTTP requests.

 

  1. Install
  2. Create
  3. Configure
  4. Deploy

 

1. Install

$ npm install -g @serverless/components

2. Create

$ mkdir mono && cd mono

The directory should look something like this:

|- serverless.yml # required
|- index.js       # required
|- package.json   # optional
|- .env           # your development AWS api keys
|- .env.prod      # your production AWS api keys

the .env files are not required if you have the aws keys set globally and you want to use a single stage, but they should look like this.

AWS_ACCESS_KEY_ID=XXX
AWS_SECRET_ACCESS_KEY=XXX

The index.js file should look something like this.

module.exports = async (e, ctx, cb) => {
  return { statusCode: 200, body: 'mono app deployed.' }
}

// you could also just return an object
// which would return it as body with
// 200 status code by default
// module.exports = () => ({ hello: 'world' })

// or just a string
// module.exports = () => 'success'

// or a status code number
// module.exports = () => 404 // not found!

// you don't even need to export a function!
// module.exports = { hello: 'world' } // great for mocking!
// module.exports = 'success'
// module.exports = 500

3. Configure

All the following inputs are optional. However, they allow you to configure your Lambda compute instance and pass environment variables.

# serverless.yml

name: mono
stage: dev

mono:
  component: "@serverless/mono"
  inputs:
    name: my-mono-app
    description: My Mono App
    region: us-east-1
    memory: 128
    timeout: 10
    env:
      TABLE_NAME: my-table

    # the directory that contains the index.js file.
    # If not provided, the default is the current working directory
    # code: ./code


4. Deploy

mono (master)$ components

  Mono › outputs:
  url:  'https://bbhm7tk587.execute-api.us-east-1.amazonaws.com/dev/'


  7s › dev › Mono › done

mono (master)$

All requests to this root url will be proxied directly to your lambda function, giving you full control of the http layer.

 

New to Components?

Checkout the Serverless Components repo for more information.