All Projects → serverless-community-labs → Serverless Plugin Simulate

serverless-community-labs / Serverless Plugin Simulate

Licence: mit
This is a proof of concept to see if we can replicate Amazon API Gateway using docker images to run lambda

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Serverless Plugin Simulate

Serverless Plugins
Collection of serverless plugins ⚡️
Stars: ✭ 126 (-1.56%)
Mutual labels:  serverless, serverless-plugin
Serverless Es Logs
A Serverless plugin to transport logs to ElasticSearch
Stars: ✭ 51 (-60.16%)
Mutual labels:  serverless, serverless-plugin
Serverless Dynalite
Serverless plugin to run Dynalite locally (No JVM needed!) to handle DynamoDB development. Can watch for table config changes.
Stars: ✭ 19 (-85.16%)
Mutual labels:  serverless, serverless-plugin
Serverless Plugin Typescript
Serverless plugin for zero-config Typescript support
Stars: ✭ 611 (+377.34%)
Mutual labels:  serverless, serverless-plugin
Serverless Plugin Git Variables
⚡️ Expose git variables to serverless
Stars: ✭ 75 (-41.41%)
Mutual labels:  serverless, serverless-plugin
Serverless Step Functions
AWS Step Functions plugin for Serverless Framework ⚡️
Stars: ✭ 758 (+492.19%)
Mutual labels:  serverless, serverless-plugin
Plugins
Serverless Plugins – Extend the Serverless Framework with these community driven plugins –
Stars: ✭ 850 (+564.06%)
Mutual labels:  serverless, serverless-plugin
Serverless Vscode
Aliyun Function Compute extension. Lets you develop your serverless application of Aliyun within VSCode.
Stars: ✭ 272 (+112.5%)
Mutual labels:  serverless, serverless-plugin
Serverless Cljs Plugin
Serverless plugin for Clojurescript deployment w/ cljs-lambda
Stars: ✭ 72 (-43.75%)
Mutual labels:  serverless, serverless-plugin
Serverless Reqvalidator Plugin
Serverless plugin to attach AWS API Gateway Basic Request Validation https://rafpe.ninja/2017/12/18/serverless-own-plugin-to-attach-aws-api-gateway-basic-request-validation/
Stars: ✭ 59 (-53.91%)
Mutual labels:  serverless, serverless-plugin
Serverless Wsgi
Serverless plugin to deploy WSGI applications (Flask/Django/Pyramid etc.) and bundle Python packages
Stars: ✭ 377 (+194.53%)
Mutual labels:  serverless, serverless-plugin
Serverless Webpack
Serverless plugin to bundle your lambdas with Webpack
Stars: ✭ 1,595 (+1146.09%)
Mutual labels:  serverless, serverless-plugin
Serverless Bundle
Optimized packages for ES6 and TypeScript Node.js Lambda functions without any configuration.
Stars: ✭ 295 (+130.47%)
Mutual labels:  serverless, serverless-plugin
Serverless Plugin Warmup
Keep your lambdas warm during winter. ♨
Stars: ✭ 814 (+535.94%)
Mutual labels:  serverless, serverless-plugin
Serverless Plugin Canary Deployments
Canary deployments for your Serverless application
Stars: ✭ 283 (+121.09%)
Mutual labels:  serverless, serverless-plugin
Serverless Python Requirements
⚡️🐍📦 Serverless plugin to bundle Python packages
Stars: ✭ 838 (+554.69%)
Mutual labels:  serverless, serverless-plugin
Mongoke
Instant Graphql for MongoDb (active branch is golang, rewrite in process)
Stars: ✭ 203 (+58.59%)
Mutual labels:  serverless, docker-compose
Serverless Chrome
🌐 Run headless Chrome/Chromium on AWS Lambda
Stars: ✭ 2,625 (+1950.78%)
Mutual labels:  serverless, serverless-plugin
Serverless Export Env
Serverless plugin to export environment variables into a .env file
Stars: ✭ 51 (-60.16%)
Mutual labels:  serverless, serverless-plugin
Serverless Docker Image Resize
Simple serverless image resize on-the-fly - Deploy with one command - Built with AWS Lambda and S3
Stars: ✭ 114 (-10.94%)
Mutual labels:  serverless, docker-compose

Serverless simulation plugin

serverless Build Status npm version Coverage Status dependencies license

This is a proof of concept to see if we can replicate Amazon API Gateway using docker images to run lambda

Features:

  • λ runtimes supported by docker-lambda.
  • CORS
  • Authorizer
    • Custom Authorizer supported
    • Coginito Authorizer not implemented yet
  • Lambda Integration
    • Velocity templates support. supported
  • Lambda Proxy Integration. supported

Prerequisite

Getting Started

Install the plugin

npm i --save-dev serverless-plugin-simulate

Configure your service to use the plugin

service: my-service
provider:
  name: aws
  runtime: nodejs4.3 # python2.7 is also supported

# this is optional configurations
# servicesPathDest is use for the case u want to compile all your src and out
# put to another folder like dist
#
# services allows specifying a docker-compose.yml file and (optional)
# projectName. This will start the docker-compose stack when simulate is run.
# If projectName is specified, it will be used when running docker-compose,
# and the default docker-compose network will be passed to lambda docker commands
# allowing all lambdas to access any hosts defined in docker-compose services
custom:
  simulate:
    dist: dist
    services:
      file: docker-compose.yml
      # will use: $ docker-compose --project-name myproject ...
      # and:      $ docker --network myproject_default ...
      projectName: myproject

plugins:
  - serverless-plugin-simulate

If you do not need to chain functions locally you can just run the API Gateway simulation by itself.

sls simulate apigateway -p 5000

Using the Lambda simulator

If you want to chain functions locally, you need to use the Lambda Simulator.

Run the Lambda Simulation

sls simulate lambda -p 4000

Run the API Gateway Simulation

sls simulate apigateway -p 5000 --lambda-port 4000

Use the environment variables to configure the AWS SDK to use the local Lambda simulation. You can use the same technique with any other AWS SDK.

const AWS = require('aws-sdk');

const endpoint = process.env.SERVERLESS_SIMULATE ?
  process.env.SERVERLESS_SIMULATE_LAMBDA_ENDPOINT :
  undefined

const lambda = new AWS.Lambda({ endpoint })
const handler = (event, context, callback) => {
  const params = {
    FunctionName: 'my-other-function',
    Payload: JSON.stringify({ foo: 'bar' })
  }
  lambda.invoke(params, (err, result) => {
    if (err) {
      return callback(err)
    }

    callback(null, {
      statusCode: 200,
      body: result.Payload
    })
  })
}

Examples

See the examples folder for examples.

  • npm install - Installs all dependencies
  • npm start - Starts API Gateway simulation listening at http://localhost:5000
  • npm run start:lambda - Starts Lambda simulation listening at http://localhost:4000
  • npm run start:apigateway - Starts API Gateway simulation that uses the Lambda simulation listening at http://localhost:5000
  • npm run start:services - Starts mock services defined in docker-compose.yml
  • npm test - tests custom authorizer (Authorization:TOKEN 12345)

Authors

See also the list of contributors who participated in this project.

Contributing

Please create an issue before submitting an Pull Request.

Acknowledgements

This would not be possible without lambci

  • docker-lambda - Docker images and test runners that replicate the live AWS Lambda environment

@johncmckim for suggesting the idea

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].