Git Product home page Git Product logo

serverless-aws-rust-multi's Introduction

serverless AWS Rust multi-function template

A sample template for bootstraping a multi function Rustlang AWS Lambda applications with โšก serverless framework โšก using Cargo workspaces

โœจ features

  • ๐Ÿฆ€ Build Rustlang applications with ease
  • ๐Ÿ›ต Continuous integration testing with GitHub Actions
  • ๐Ÿš€ Continuous deployment with GitHub Actions
  • ๐Ÿงช Getting started unit tests

๐Ÿ“ฆ install

Install the serverless framework cli.

Then then run the following in your terminal

$ npx serverless install \
  --url https://github.com/softprops/serverless-aws-rust-multi \
  --name my-new-multi-func-app

This will download the source of a sample Rustlang application and unpack it as a new service named "my-new-multi-func-app" in a directory called "my-new-multi-func-app"

๐Ÿง™ how to be a wizard

Assuming you have aws credentials with appropriate deployment permissions configured (if you already use any existing AWS tooling installed you likely already have this configured), you could impress your friends by creating a project that is born in production.

$ npx serverless install \
  --url https://github.com/softprops/serverless-aws-rust-multi \
  --name my-new-multi-func-app \
  && cd my-new-multi-func-app \
  && npm ci \
  && npx serverless deploy

npm ci will make sure npm dependencies are installed based directly on your package-lock.json file. This only needs run once. The first time you run npx serverless deploy it will pull down and compile the base set of dependencies and your application. Unless the dependencies change afterwards, this should only happen once, resulting in an out of the box rapid deployment cycle.

๐Ÿ›ต continuous integration and deployment

This template includes an example GitHub actions configuration file which can unlock a virtuous cycle of continuous integration and deployment ( i.e all tests are run on prs and every push to master results in a deployment ).

GitHub actions is managed simply by the presence of a file checked into your repository. To set up GitHub Actions to deploy to AWS you'll need to do a few things

Firstly, version control your source. Github is free for opensource.

$ git init
$ git remote add origin [email protected]:{username}/{my-new-service}.git

Store a AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY used for aws deployment in your repositories secrets https://github.com/{username}/{my-new-service}/settings/secrets

Add your changes to git and push them to GitHub.

Finally, open https://github.com/{username}/{my-new-service}/actions in your browser and grab a bucket of popcorn ๐Ÿฟ

๐Ÿ”ซ function triggering

With your function deployed you can now start triggering it using serverless framework directly or the AWS integration you've configured to trigger it on your behalf

$ npx serverless invoke -f hello -d '{"foo":"bar"}'

๐Ÿ”ฌ logs

With your function deployed you can now tail it's logs right from your project

$ npx serverless logs -f hello
$ npx serverless logs -f world

๐Ÿ‘ด retiring

Good code should be easily replaceable. Good code is should also be easily disposable. Retiring applications should be as easy as creating and deploying them them. The dual of serverless deploy is serverless remove. Use this for retiring services and cleaning up resources.

$ npx serverless remove

โ„น๏ธ additional information

๐Ÿ‘ฏ Contributing

This template's intent is to set a minimal baseline for getting engineers up an running with a set of repeatable best practices. See something you'd like in this template that would help others? Feel free to open a new GitHub issue. Pull requests are also welcome.

serverless-aws-rust-multi's People

Contributors

softprops avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

serverless-aws-rust-multi's Issues

How to `serverless invoke local`?

I ran serverless invoke local -f hello, and got this error:

  Error --------------------------------------------------
 
  Error: no Rust functions found. Use 'runtime: rust' in global or function configuration to use this plugin.
 
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     OS:                     darwin
     Node Version:           10.15.3
     Serverless Version:     1.41.1

Is it possible to invoke this function locally?

Add unit-testing example for POST requests

Hi,

I'm trying to write a unit test for a POST request handler that echos a JSON payload.

I'm expecting to be able to set the method, headers, etc (similar to the request builder as described in the http crate documentation) but I get error messages like the following:

error[E0599]: no method named `header` found for type `http::request::Request<lambda_http::body::Body>` in the current scope
  --> src/create.rs:43:14
   |
43 |             .header("Content-Type", "application/json");
   |              ^^^^^^
   |
   = help: did you mean `headers`?

Can you point me to any documentation that may help with this?

My code attached for background:

#[macro_use]
extern crate serde_derive;

use lambda_http::{lambda, IntoResponse, Request, Body};
use lambda_runtime::{error::HandlerError, Context};

use serde;
use serde_json::{json, Value, Error};
use serde_dynamodb;
use uuid;
use rusoto_core;
use rusoto_dynamodb;

mod rsvp;

fn main() {
    lambda!(create_handler)
}

fn create_handler(
    request: Request,
    _context: Context,
) -> Result<impl IntoResponse, HandlerError> {

    println!("{:?}", request);

    return Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_create_handler() {

        let body = "{'hello': 'world'}";

        let request = Request::new(Body::from(body.clone()))
            .header("Content-Type", "application/json");

        let response = create_handler(request, Context::default())
            .expect("expected Ok(_) value")
            .into_response();

        println!("{:?}", response);
    }
}

How to deploy individual function?

I try to deploy only one function but it isn't working. I got the message. I also try both options are dockerless and docker.
The command I run sls deploy -f v2_store_detail --env staging
image

How to include a shared code crate?

Hi there..

I'm new to rust and serverless. I've been trying to create a collection of functions using this template. One of the things that I would like to be able to do is have a common crate that's shared across all my functions.
I'm unsure how to structure the code so that I can include this shared crate so that it builds..

My current setup is

mycommon
  - src
myapp
 - serverless.yml
 - hello

  - Cargo.toml
   - src
     - main.rs
    - Cargo.toml
  - world
    -src
      - main.rs
   -  Cargo.toml

When the build tries to run the docker container can't find the files.

How do other folks deal with this? Any help here would be really appreciated.

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.