State persistence for AWS Lambda MicroVMs with Amazon S3

Amazon API Gateway → Session middleware → AWS Lambda MicroVMs → Amazon DynamoDB → Amazon S3

A Sticky Notes Board that shows Lambda MicroVM state persistence: notes and files survive a MicroVM terminating and relaunching, restored from S3 per client.

This pattern demonstrates Lambda MicroVMs state persistence. A user adds sticky notes and uploads files inside a Firecracker MicroVM. When the MicroVM is terminated and a new one launches for the same user, everything is restored.
A static web UI talks only to an Amazon API Gateway HTTP API backed by a session-middleware Lambda. The middleware owns the MicroVM lifecycle and auth tokens, it tracks sessions by clientId in Amazon DynamoDB and reverse-proxies all /api/* calls to the client's MicroVM, injecting the auth token server-side.
The MicroVM runs a notes + files REST API plus lifecycle hooks. Notes live in memory and uploaded files in the MicroVM's local filesystem while it runs. State is persisted to Amazon S3 only at lifecycle boundaries: the suspend and terminate hooks push notes and files to S3, and the run hook restores both on boot.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/lambda-microvms-state-persistence-with-s3/python/cloudformation

Deploy

./deploy.shAWS_REGION=us-east-1 STACK_NAME=my-notes ./deploy.sh


Testing

Serve the UI: (cd web && python3 -m http.server 5173), then open http://localhost:5173.
Paste the Middleware URL from deploy.sh, enter a Client ID, and open the workspace. Add notes and upload a file.
Switch workspace (state flushes to S3), reopen with the same Client ID, and confirm the notes and files are restored from S3.

Cleanup

Terminate any running MicroVMs for this image (they are created at runtime, not by the stack).
Delete the stack: aws cloudformation delete-stack --stack-name .
Empty and remove the S3 state bucket: aws s3 rb s3:// --force.

Created by:

Ricardo Marques

Ricardo Marques

Principal Serverless Specialist, AWS

Follow on LinkedIn