A home project to help me learn more about Rust in a serverless environment.
This is very much a work in progress.
- GraphQL server
- REST services
- DynamoDB backend
I've been trying to overcome the issues developing in serverless by writing and running the code locally. This also allows me to easily debug the code (see VSCODE debug config).
Currently these means building 2 versions of the executable - one for local development (local**) and one for AWS Lambda (lambda**).
I've created 3 configurations for this, all running in Docker containers (for now).
make docker.start.dynamodb
NOTE - if this is the first time running this, you'll need to run the following to create the table:
make dynamodb.table.create
Sclylla DB running with DynamoDB compatibility mode (https://www.scylladb.com)
make docker.start.scylladb
NOTE - if this is the first time running this, you'll need to run the following to create the table:
make dynamodb.table.create
Localstack (https://localstack.cloud)
make docker.start.localstack
Additionally you can build and deploy the whole project to localstack with the following command:
make release.deploy
The Terraform output will give the generated urls for the GraphQL and Rest services.
NOTE - if not already set up, you will need to run make terraform.init
first to configure the terraform modules.
This has been written on a Mac but should work on Linux.
To cross compile onto Linux there are a couple of dependencies to install:
brew install filosottile/musl-cross/musl-cross
rustup component add rust-std-x86_64-unknown-linux-musl
Update the Cargo config to use the musl toolchain (~/.cargo/config):
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
To build the code for local development:
make build
The build the code for AWS Lambda:
make release
mutation product ($args: NewProduct!) {
createProduct(newProduct: $args) {
key
name
description
price {
amount
currencyCode
}
}
}
query {
viewProduct(key: "e83bb923-293b-4795-be51-3b0770d9c6d2") {
key
name
description
price {
amount
currencyCode
}
}
}
POST http://localhost:8081
{
"key": "{{$randomUUID}}",
"name": "{{$randomProductName}}",
"price": {
"currency_code": "GBP",
"amount": {{$randomPrice}}
},
"description": "{{$randomLoremWords}}"
}
POST http://localhost:8082
{
"key": "{{$randomUUID}}",
"inventory": {{$randomInt}}
}