rust-lambda-graphql-example
rust-lambda-graphql-example copied to clipboard
An example GraphQL API written in Rust that can be deployed to AWS Lambda via CDK
rust-lambda-graphql-example
A super simple example GraphQL API that can be hosted on AWS Lambda.
What's in the box?
srccontains the code to integrate theasync-graphqlcrate with thelamedhcrates for a serverless GraphQL experience. You can hit the root/path to see aGraphiQLUI or the/graphqlpath to make queries.- The
cdkdirectory contains all the infrastructure as code,cdk/cdk.tsis where you'll want to tweak your own infrastructure. Makefile.tomlcontains a couple useful rules for working with this project (usescargo-make).docker-compose.ymlcontains a basic Postgres setup that all the rules in this project use for testing/running.
To Set Up (macOS)
- Install node:
brew install node - Install node dependencies:
npm install --prefix cdk - Install cargo-make:
cargo install cargo-make - Install AWS SAM CLI for local development:
pipx install aws-sam-cli(orpiporbrewif you prefer) - Setup MUSL cross-compile toolchain (since that's what lambda runtime needs):
- Add MUSL target:
rustup target add x86_64-unknown-linux-musl - Install MUSL cross-compile tool:
brew install FiloSottile/musl-cross/musl-cross - Soft link musl-gcc:
ln -s /usr/local/bin/x86_64-linux-musl-gcc /usr/local/bin/musl-gcc
- Add MUSL target:
How to use?
- Use
makers localto run the API locally. This will use CDK to generate a template for SAM CLI, then use SAM CLI to run locally. This rule requires Docker and SAM CLI to be installed. - Use
makers deployto deploy to AWS with your default profile. You have to have AWS credentials set up. Modify package.json or Makefile.toml if you want to use a different profile.- If you have not used
npm exec --prefix cdk cdk bootstrapbefore on you account, you'll need to run this once. - Use
npm exec --prefix cdk cdk destroyto tear down the API. You may have to find and empty the generated S3 bucket manually for this to work. This will not destroy the stack created bybootstrap, you have to do that yourself in CloudFormation if you want it gone.
- If you have not used
Roadmap
What am I planning on evolving this into?
- [x] Add example database handling.
- [x] Add logging via
tracingcrate or similar.