Giter VIP home page Giter VIP logo

aws-cdk-with-rust's Introduction

AWS CDK with Rust

This project shows you how to use Rust in Lambda function and how to deploy them by AWS CDK.

The stack will deploy

Pre-requirements

For the deployment, rust toolchain is not required since we use docker as a builder.

Deployment

Before the cdk deployment, you need to create assets of rust projects for lambda functions. Use the build script at build.sh.

./bulid.sh

Next, deploy the cdk stack. Read the Getting Started guide if you need.

# If you never bootstrap your AWS account for cdk, you need to do it.
cdk bootstrap

# Intall the dependencies
npm install

# Deploy it!
cdk deploy

Check the API

We deployed "Fitness Training Score" API, that is, store the latset score of the training for each users. The storing data structure have username (string), version (string), age (integer), and score (integer) as attributes.

Let's store the first score.

# Replace <API_ID> and <REGION>
export API_ENDPOINT=https://<API_ID>.execute-api.<REGION>.amazonaws.com/prod

curl \
    -v -XPOST \
    -d '{"username":"user0","version":"0","age":23,"score":87}' \
    -H "Content-Type:application/json" \
    ${API_ENDPOINT}/fitness

You will get {"success":true} if it's success. The Amazon DynamoDB database have the username as a partitionKey and the version as a sortKey. Basically the version is fixed "0". So you need to change username to store other data. Please add other data with changing username, age and score.

Let's query the results you stored. You can specify version, sort, order, min_score, max_score, min_age, and max_age where

  • the version is the training version that is fixed "0".
  • the sort can specify the sort key that is one of the "score" or "age". (the default is "score".)
  • the order can specify the order that is one of "desc" or "asc". (the default is "asc".)
  • min_* and max_* can specify the range.
    • min_age and max_age will be ignored if you specify sort=score.
    • min_score and max_score will be ignored if you specify sort=age.

For example, the query below will get "the results of the training version 0 sorted by the score and ordered by desc. The score range is from 70 to 100."

curl -v "${API_ENDPOINT}/fitness?version=0&sort=score&order=desc&min_score=70&max_score=100"

About Rust projects structure

This section describes how to construct the rust projects and lambda directory. We use workspace to create multiple binaries. See lambda/Cargo.toml Alternatively, we can use [[bin]] section to create multiple binaries in one project.

fitness-score-def is a common structure definition that is used in fitness-score-get and fitness-score-store. It doesn't create a binary since it's a library. fitness-score-get and fitness-score-store will be the AWS Lambda functions.

Clean

Execute below.

cdk destroy

aws-cdk-with-rust's People

Contributors

amazon-auto avatar tbrandaws avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

donmagee

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.