GithubHelp home page GithubHelp logo

happyspace / rust-happy Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 1.96 MB

AWS Dev Hour Project with a Rush backend :)

JavaScript 12.45% TypeScript 68.71% Shell 12.26% Perl 2.63% Dockerfile 0.53% Rust 3.43%
rust lambda-functions aws-cdk bootstrap

rust-happy's Introduction

Welcome to Rust Happy "AWS Dev Hour: Building Modern Applications" with the backend Lambda function implemented in Rust

The following project follows AWS Dev Hour: Building Modern Applications We build out our cloud application infrastructure using CDK. Our backend code will be implemented in Rust. We include the rust code in this project as a mono-repo to make building and deploying ergonomic. For a real world project we would likely separate these concerns.

Things We Need to Setup

Follow directions to install the following for your host platform.

Windows Users

If we would like to package our lambdas on the Windows side, use this utility to create the zip file correctly.

Get build-lambda-zip

go.exe get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip

Building nativity on Windows

TODO: install OpenSSL and build the Rust OpenSSL crate.

Visual Studio Code -- Standard Rust Container

TODO: Explore using Visual Studio Code Standard Rust Container

Docker

Build

Build an image for building our lambdas based on the official Rust template for Alpine Linux. To this we add build-base, openssl-dev, git and zip.

docker build -t happyspace/rust-happy .

Run

docker run --rm -it -v "$(pwd):/usr/src/app" happyspace/rust-happy

Build lambda code interactively in the container

cargo build --bin rekognition --release --target x86_64-unknown-linux-musl

Package lambda code for deployment

For custom AWS lambda runtimes, we follow the convention described in the docs:

  • Include a runtime 'in the form of an executable file named bootstrap'
  • A lambda function, in our case compiled into our runtime bootstrap

We will package our lambda functions in .zip archives for deployment through AWS CDK.

Package lambda interactively in our container

cp ./target/x86_64-unknown-linux-musl/release/rekognition ./bootstrap && zip rekognition.zip bootstrap && rm bootstrap && mv -f rekognition.zip ./lambda/

Note to Windows Users

Our bootstrap file must be executable, which will not be preserved creating the '.zip' file in Windows context. Use the 'build-lambda-zip utility to create a zip file that does preserved the executable status of our bootstrap file.

cp ./target/x86_64-unknown-linux-musl/release/rekognition ./bootstrap
~\Go\Bin\build-lambda-zip.exe -output rekognition.zip bootstrap
mv -force rekognition.zip ./lambda/ && rm bootstrap

CDK: how we will manage our lambda code

Once we have created our build context in Docker, built and packaged our lambda functions: we are ready to deploy the code through AWS CDK.

cdk synth
cdk deploy

CDK configuration for Rust lambdas

'runtime: Runtime.PROVIDED_AL2,' tells cloud formation that we are providing the runtime and that this runtime should run on Amazon Linux 2 (the 'AL2' suffix).

    const rekognitionFunction = new lambda.Function(this, "rekognitionFunction", {
      code: lambda.Code.fromAsset("lambda//rekognition.zip"),
      runtime: Runtime.PROVIDED_AL2,
      handler: "doesnt.matter",
      timeout: Duration.seconds(30),
      memorySize: 1024,
      environment: {
        "TABLE": this.tableImage.tableName,
        "BUCKET": this.bucketImage.bucketName,
        RUST_BACKTRACE: "1",
      },
    });

The cdk.json file tells the CDK Toolkit how to execute your app.

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk synth emits the synthesized CloudFormation template

Rust

Rusoto cargo configuration

For our Rusoto clients it is important to enable the use of 'rustls' which removes a dependence on openssl for crypto functions.

rusoto_core = {version = "0.46.0", default_features = false, features=["rustls"]}
rusoto_s3 = {version = "0.46.0", default_features = false, features=["rustls"]}
rusoto_sqs = {version = "0.46.0", default_features = false, features=["rustls"]}
rusoto_dynamodb = {version = "0.46.0", default_features = false, features=["rustls"]}

rust-happy's People

Contributors

happyspace avatar

Watchers

 avatar James Cloos 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.