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 --arm64This 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 synthUpdating 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 -vSee https://yarnpkg.com/getting-started/install.
# assuming you have already run:
# corepack enable
yarn set version stableyarn up -i '*' '@*/*'cargo update
cargo upgradeThe cdk.json file tells the CDK Toolkit how to execute your app.
yarn buildcompile typescript to jsyarn watchwatch for changes and compileyarn testperform the jest unit testsyarn cdk deploydeploy this stack to your default AWS account/regionyarn cdk diffcompare deployed stack with current stateyarn cdk synthemits the synthesized CloudFormation template