/walk-the-world-backend

Small app for counting steps. Built on AWS using serverless Rust.

Primary LanguageRust

Walk The World Backend

This is a backend for a trivial web application: the idea is for users to add their daily steps, which is aggregated towards the goal of walking around the world.

This served as a nice first project for working with Rust and serverless infrastructure.

Features

  • ๐Ÿฆ€ Rust ๐Ÿ™
  • ๐Ÿ”“ Cognito for login and identity management
  • ๐Ÿš€ API Gateway REST API (with request body validation to prevent failed lambda invocations)
  • ๐Ÿงจ DynamoDb
  • ๐Ÿ›  Staged deployments for everything!

๐Ÿ“ฆ Development

Install the serverless framework cli.

Run npm ci, which will make sure npm dependencies are installed based directly on your package-lock.json file. This only needs run once. The first time you run npx serverless deploy it will pull down and compile the base set of dependencies and your application. Unless the dependencies change afterwards, this should only happen once, resulting in an out of the box rapid deployment cycle.

๐Ÿ›ต Continuous integration and deployment

TODO using Github actions

Local deployment

serverless deploy -v

The -v is important as this will print out all the created resources from cloudformation. These resources are then environment variables for the frontend.

Creating a user

Either use a real signup flow or create a user using the aws cli

aws cognito-idp sign-up \
  --region YOUR_COGNITO_REGION \
  --client-id YOUR_COGNITO_APP_CLIENT_ID \
  --username admin@example.com \
  --password Passw0rd!

And then verify the user

aws cognito-idp admin-confirm-sign-up \
  --region YOUR_COGNITO_REGION \
  --user-pool-id YOUR_COGNITO_USER_POOL_ID \
  --username admin@example.com

๐Ÿ”ฌ Logs

With your function deployed you can now tail it's logs right from your project

$ npx serverless logs -f $FUNCTION_NAME

๐Ÿ‘ด Retiring

Good code should be easily replaceable. Good code is should also be easily disposable. Retiring applications should be as easy as creating and deploying them them. The dual of serverless deploy is serverless remove. Use this for retiring services and cleaning up resources.

$ npx serverless remove

โ„น๏ธ Additional information

This was bootstrapped from this Rust serverless template.