GithubHelp home page GithubHelp logo

example-rocket-lamb-api's Introduction

๐Ÿš€ Example Rocket Lamb API ๐Ÿ‘

A simple web API written using Rocket, with two binaries:

  • main, a normal application which you can run locally for testing
  • lambda, written to be run as an AWS Lambda function, using Rocket Lamb

It has two endpoints defined:

  • / (the root path) - returns Hello world as a plaintext response
  • /rocket - returns a PNG image

Deploying to AWS Lambda

Deployment can be done using AWS CloudFormation using the Serverless Application Model. The required CloudFormation template is already set up in template.yaml.

Requirements:

  • Docker
  • AWS CLI
  • An existing S3 bucket
# Builds the lambda binary in a Docker container and outputs the packaged zip file
docker-compose run --rm build

S3_BUCKET=my-s3-bucket-name
# Choose any name you like for the CloudFormation stack
STACK_NAME=my-rocket-api

# Uploads the CloudFormation template and zipped binary to S3
aws cloudformation package --template-file template.yaml --output-template-file packaged.yaml --s3-bucket $S3_BUCKET

# Deploys the CloudFormation stack
aws cloudformation deploy --template-file packaged.yaml --capabilities CAPABILITY_IAM --stack-name $STACK_NAME

# Outputs the API Gateway URL that you can use to call your API
aws cloudformation describe-stacks --query "Stacks[0].Outputs" --stack-name $STACK_NAME

Testing Locally

The easiest way of running the application locally is just with cargo run, which will run main.rs. This configures and launches a bog-standard Rocket server, without using Rocket Lamb.

Another way is to use the AWS SAM CLI, which can be used to spin up a fake lambda environment in Docker with a mock API Gateway. While more of a hassle to run, this will also test both the CloudFormation configuration in template.yaml, and the application's integration with Lambda and API Gateway. To run the app using the SAM CLI:

docker-compose run --rm build

sam local start-api

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.