# serverless-rust-plugin

> A Serverless Framework plugin for Rust using Cargo Lambda.

Latest version **0.3.3** (published 2023-11-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install serverless-rust-plugin
pnpm add serverless-rust-plugin
yarn add serverless-rust-plugin
bun add serverless-rust-plugin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.3 |
| Published | 2023-11-29 |
| First published | 2022-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 41.3 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 7 |
| Author | kaicoh |
| Maintainers | kaicoh |
| Keywords | rust, aws, aws-lambda, serverless, serverless-plugin, lambda |

## Links

- npm: https://www.npmjs.com/package/serverless-rust-plugin
- Repository: https://github.com/kaicoh/serverless-rust-plugin
- Homepage: https://github.com/kaicoh/serverless-rust-plugin#readme
- Issues: https://github.com/kaicoh/serverless-rust-plugin/issues
- npm.io page: https://npm.io/package/serverless-rust-plugin

## Dependencies (5)

- [rxjs](https://npm.io/package/rxjs.md) ^7.5.7
- [toml](https://npm.io/package/toml.md) ^3.0.0
- [table](https://npm.io/package/table.md) ^6.8.1
- [lodash.get](https://npm.io/package/lodash.get.md) ^4.4.2
- [serverless](https://npm.io/package/serverless.md) 3

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.3.3 (latest) — 2023-11-29
- 0.3.2 — 2023-10-09
- 0.3.1 — 2023-10-04
- 0.3.0 — 2022-12-02
- 0.2.3 — 2022-11-26
- 0.2.2 — 2022-11-25
- 0.2.1 — 2022-11-23
- 0.2.0 — 2022-11-22
- 0.1.2 — 2022-11-19
- 0.1.1 — 2022-11-19
- 0.1.0 — 2022-11-19

## README

# serverless-rust-plugin

[![Serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com)
[![main](https://github.com/kaicoh/serverless-rust-plugin/actions/workflows/test.yml/badge.svg)](https://github.com/kaicoh/serverless-rust-plugin/actions)
[![Coverage Status](https://coveralls.io/repos/github/kaicoh/serverless-rust-plugin/badge.svg?branch=main)](https://coveralls.io/github/kaicoh/serverless-rust-plugin?branch=main)

A [Serverless Framework](https://www.serverless.com/) plugin for [Rust](https://www.rust-lang.org/) using [Cargo Lambda](https://www.cargo-lambda.info/)

## 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](https://github.com/awslabs/aws-lambda-rust-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](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](https://github.com/cargo-lambda/cargo-lambda/pkgs/container/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](docs).

```
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](docs/rust:start).

```
$ 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](docs/rust:ps).

```
$ 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](docs/rust:invoke).

```
$ 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](docs/rust:logs).

```
$ 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](docs/rust:stop).

```
$ serverless rust:stop

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

## License

This software is released under the [MIT License](LICENSE).

---
_Source: https://npm.io/package/serverless-rust-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
