seankrail.dev's backend
My personal website's backend built using TypeScript, AWS CDK, and Rust, hosted on AWS Lambda and DynamoDB, and continuously deployed by GitHub Actions.
Right now, it just provides an endpoint to increment a count, but plan to host more interesting features and experiments in the future.
There's a Lambda function written in Rust located at functions/counter
. There you can run normal cargo
commands to build, test, etc. You'll also need to install Cargo Lambda in your development environment. It's used to build a target for the Lambda environment.
cargo lambda build --release --arm64
This produces target/lambda/counter/bootstrap
. This is referenced in our CounterStack at lib/counter-stack.ts
. The target/lambda/counter
directory is zipped, uploaded to S3, and then used to run the Lambda function.
The CDK components are split into three parts: bin/
, lib/
, test/
. bin/
holds the CDK entrypoint. It instantiates our CDK App and creates the CounterStack (referencing lib/counter-stack.ts
). The CDK CLI generates the CloudFormation templates from it. lib/
is where we define our CDK constructs and stacks referenced in bin/website-backend.ts
. test/
holds the unit tests for lib/
resources.
For example, to build everything and synthesize the Cfn templates, run:
yarn build-function
yarn build
yarn cdk synth
Updating node via mise
There's a `.mise.toml in this project root, so all you need to run is:
mise use node@20
node -v
npm -v
See https://yarnpkg.com/getting-started/install.
# assuming you have already run:
# corepack enable
yarn set version stable
yarn up -i '*' '@*/*'
cargo update
cargo upgrade
The cdk.json
file tells the CDK Toolkit how to execute your app.
yarn build
compile typescript to jsyarn watch
watch for changes and compileyarn test
perform the jest unit testsyarn cdk deploy
deploy this stack to your default AWS account/regionyarn cdk diff
compare deployed stack with current stateyarn cdk synth
emits the synthesized CloudFormation template