GithubHelp home page GithubHelp logo

chouandy / serverless-rust-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kaicoh/serverless-rust-plugin

0.0 1.0 0.0 2.01 MB

A Serverless Framework plugin for Rust using Cargo Lambda.

License: MIT License

JavaScript 99.85% Rust 0.15%

serverless-rust-plugin's Introduction

serverless-rust-plugin

Serverless main Coverage Status

A Serverless Framework plugin for Rust using Cargo Lambda

Requirement

This plugin has peer dependency, serverless framework v3.

Installation

Run this command.

$ npm install --save-dev serverless-rust-plugin

And add the following to your serverless.yml file

provider:
  name: aws
  runtime: provided.al2
  # this plugin reads this property and passes it to cargo lambda.
  # default is x86_64.
  architecture: arm64
plugins
  - serverless-rust-plugin
functions:
  hello:
    # handler value syntax is `{cargo-package-name}.{bin-name}`
    # or `{cargo-package-name}` for short when you are building a
    # default bin for a given package.
    handler: your-cargo-package-name

In documents of AWS Lambda Runtime the handler is set to be bootstrap. This plugin renames the handler in deployment process so you don't have to worry about it.

Example projects

See examples.

Usage

Deployment

$ serverless deploy

By default this plugin uses docker container to build. Make sure you have a docker daemon running. But if your local machine installs cargo lambda, you can use it by the following configuration.

Configuration for build

provider:
  name: aws
  architecture: arm64

custom:
  rust:
    cargoLambda:
      docker: false
      profile: debug
option path in serverless.yml values description
architecture provider.architecture x86_64, arm64 The architecture cargo lambda compiles for. default is x86_64.
docker custom.rust.cargoLambda.docker boolean Use docker to compile or not. If true, this plugin uses cargo-lambda/cargo-lambda otherwise cargo lambda in your local machine.
profile custom.rust.cargoLambda.profile release, debug The mode cargo lambda compiles. default is release.

Local Test

Using docker, this plugin has some commands for testing your lambda functions locally. These commands use docker regardless of the setting for cargo lambda build. (Local testing is nothing to do with custom.rust.cargoLambda.docker in serverless.yml.) For more info, see this.

service: my-service

provider:
  name: aws
  runtime: provided.al2
  architecture: arm64

plugins
  - serverless-rust-plugin

custom:
  rust:
    cargoLambda:
      docker: false
    local:
      envFile: .env.global
      dockerArgs: --network my-network-global

functions:
  rustFunc0:
    handler: cargo-package.bin0
    rust:
      port: 8080
      envFile: .env.local
      dockerArgs: --network my-network-local

  rustFunc1:
    handler: cargo-package.bin1

  nonRustFunc:
    handler: non-of-the-above

rust:start

Start the docker container according to the configuration in serverless.yml and show the status for each container. For more information about configurations and options for this command see this.

$ serverless rust:start
...
    Finished release [optimized] target(s) in 0.83s

╔════════════╤══════════════════════╤═════════╤═══════════════════════════╗
║ FUNCTION   │ CONTAINER NAME       │ STATUS  │ PORTS                     ║
╟────────────┼──────────────────────┼─────────┼───────────────────────────╢
║ rustFunc0  │ my-service_rustFunc0 │ running │ 0.0.0.0:8080 -> 8080/tcp  ║
╟────────────┼──────────────────────┼─────────┼───────────────────────────╢
║ rustFunc1  │ my-service_rustFunc1 │ running │ 0.0.0.0:60702 -> 8080/tcp ║
╚════════════╧══════════════════════╧═════════╧═══════════════════════════╝

rust:ps

Show the status for each container. For more information about configurations and options for this command see this.

$ serverless rust:ps

╔════════════╤══════════════════════╤═════════╤═══════════════════════════╗
║ FUNCTION   │ CONTAINER NAME       │ STATUS  │ PORTS                     ║
╟────────────┼──────────────────────┼─────────┼───────────────────────────╢
║ rustFunc0  │ my-service_rustFunc0 │ running │ 0.0.0.0:8080 -> 8080/tcp  ║
╟────────────┼──────────────────────┼─────────┼───────────────────────────╢
║ rustFunc1  │ my-service_rustFunc1 │ running │ 0.0.0.0:60702 -> 8080/tcp ║
╚════════════╧══════════════════════╧═════════╧═══════════════════════════╝

rust:invoke

Invoke lambda function and show output. For more information about configurations and options for this command see this.

$ serverless rust:invoke -f rustFunc0 -d '{"firstName":"Mary"}'
...
    Finished release [optimized] target(s) in 0.39s

{"message":"Hi, Mary!"}

rust:logs

Show logs of lambda functions. For more information about configurations and options for this command see this.

$ serverless rust:logs
rustFunc1  | START RequestId: 67394de9-1577-4ebd-be58-ba4237b71ef1 Version: $LATEST
rustFunc1  | END RequestId: 67394de9-1577-4ebd-be58-ba4237b71ef1
rustFunc1  | REPORT RequestId: 67394de9-1577-4ebd-be58-ba4237b71ef1	Init Duration: 4.09 ms	Duration: 237.96 ms	Billed Duration: 238 ms	Memory Size: 3008 MB	Max Memory Used: 3008 MB
rustFunc0  | START RequestId: e85bd375-77cf-411a-b31b-08170a454a62 Version: $LATEST
rustFunc0  | END RequestId: e85bd375-77cf-411a-b31b-08170a454a62
rustFunc0  | REPORT RequestId: e85bd375-77cf-411a-b31b-08170a454a62	Init Duration: 4.28 ms	Duration: 240.70 ms	Billed Duration: 241 ms	Memory Size: 3008 MB	Max Memory Used: 3008 MB
rustFunc0  | START RequestId: 0a3e927b-8ff2-456a-9691-5003b7e1004e Version: $LATEST
rustFunc0  | END RequestId: 0a3e927b-8ff2-456a-9691-5003b7e1004e
rustFunc0  | REPORT RequestId: 0a3e927b-8ff2-456a-9691-5003b7e1004e	Duration: 40.65 ms	Billed Duration: 41 ms	Memory Size: 3008 MB	Max Memory Used: 3008 MB

rust:stop

Stop containers and show the status. For more information about configurations and options for this command see this.

$ serverless rust:stop

╔════════════╤════════════════╤═══════════╤═══════╗
║ FUNCTION   │ CONTAINER NAME │ STATUS    │ PORTS ║
╟────────────┼────────────────┼───────────┼───────╢
║ rustFunc0  │                │ not exist │       ║
╟────────────┼────────────────┼───────────┼───────╢
║ rustFunc1  │                │ not exist │       ║
╚════════════╧════════════════╧═══════════╧═══════╝

License

This software is released under the MIT License.

serverless-rust-plugin's People

Contributors

knjtnk avatar kaicoh avatar jeffersd avatar chouandy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.