Skip to content

Add Lambda MicroVMs with S3 Files pattern#3206

Open
bfreiberg wants to merge 5 commits into
aws-samples:mainfrom
bfreiberg:lambda-microvm-s3files
Open

Add Lambda MicroVMs with S3 Files pattern#3206
bfreiberg wants to merge 5 commits into
aws-samples:mainfrom
bfreiberg:lambda-microvm-s3files

Conversation

@bfreiberg

@bfreiberg bfreiberg commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

AWS Lambda MicroVMs with Amazon S3 Files

Adds lambda-microvm-s3files/ — a pattern that mounts an Amazon S3 bucket as a POSIX file system inside an AWS Lambda MicroVM (Firecracker-isolated, snapshot-resumable serverless compute) over NFS, reachable through a VPC egress network connector, with changes synchronized to and from S3 in both directions.

How it works

  • CloudFormation (AWS SAM) provisions everything that has a resource type: the data S3::Bucket (versioning on), the S3Files::FileSystem / MountTarget / AccessPoint, the NFS security group, the Lambda::NetworkConnector (VPC egress), the IAM roles, the CloudWatch log group, and the Lambda::MicrovmImage.
  • A small src/run.sh helper performs the two data-plane steps that have no CloudFormation resource: packaging/uploading the app artifact (read by the image build) and launching the MicroVM via RunMicrovm + minting an auth token.
  • The S3 Files mount happens in the MicroVM's /run lifecycle hook (the VPC connector and execution-role credentials only exist at run time), and re-mounts on /resume.

Contents

  • template.yaml — the SAM/CloudFormation template
  • example-pattern.json — Serverless Land metadata
  • src/app.py (Flask app + lifecycle hooks), Dockerfile (AL2023 + amazon-efs-utils), run.sh
  • README.md — requirements, deployment, how-it-works, testing, cleanup

Testing

Verified end-to-end in us-west-2: sam deployrun.sh run ("mounted": true) → run.sh prove confirms bidirectional sync (a file written through the mount appears in S3; a file written to S3 is read back through the mount).

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT-0 license.

Mount an Amazon S3 bucket as a POSIX file system inside an AWS Lambda MicroVM
(Firecracker-isolated, snapshot-resumable serverless compute) over NFS, reachable
through a VPC egress network connector, with bidirectional S3 sync.

CloudFormation (AWS SAM) provisions the data bucket, the S3 Files file system /
mount target / access point, the VPC egress network connector, the IAM roles,
the CloudWatch log group, and the MicroVM image (AWS::Lambda::MicrovmImage). A
small src/run.sh helper performs the data-plane steps that have no CloudFormation
resource: packaging the app artifact and launching the MicroVM (RunMicrovm).

Verified end-to-end in us-west-2: deploy -> run -> bidirectional S3 Files sync.
@bfreiberg bfreiberg marked this pull request as ready for review June 30, 2026 17:46

@marcojahn marcojahn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bfreiberg, thank you for your contribution. I made a few request for changes. Please review.

Comment thread lambda-microvm-s3files/README.md Outdated
* **Stack Name** – e.g. `lambda-microvm-s3files`
* **AWS Region** – `us-west-2`
* **CodeArtifactBucket** – the bucket name from step 3
* **VpcId** / **SubnetId** – a VPC and subnet for the mount target and egress connector ENIs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please indicate more prominently that a VPC and Subnet needs either to be provided OR generated
Subnet requirements, private / public?

Comment thread lambda-microvm-s3files/README.md Outdated
* **CodeArtifactBucket** – the bucket name from step 3
* **VpcId** / **SubnetId** – a VPC and subnet for the mount target and egress connector ENIs
* Accept the IAM-capabilities prompt (`CAPABILITY_IAM`)
6. Note the stack outputs (`ImageArn`, `ExecutionRoleArn`, `EgressConnectorArn`, `FileSystemId`, `AccessPointId`, `MountTargetId`, `DataBucket`). The image build is asynchronous; wait until `ImageState` is `CREATED`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what for? never re-used later. Or just for FYI to show what has been created?

Comment thread lambda-microvm-s3files/README.md Outdated
@@ -0,0 +1,138 @@
# Lambda MicroVMs with S3 Files

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Lambda MicroVMs with S3 Files
# AWS Lambda MicroVMs with Amazon S3 Files

Comment thread lambda-microvm-s3files/template.yaml
Comment thread lambda-microvm-s3files/README.md Outdated
## Requirements

* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured. Upgrade the CLI if you encounter command not found errors.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we have a hard minimum requirement on the CLI version

too old
❯ aws --version
aws-cli/2.32.34 Python/3.13.11 Darwin/25.5.0 exe/arm64

working
❯ aws --version
aws-cli/2.35.16 Python/3.14.5 Darwin/25.5.0 exe/arm64

Comment thread lambda-microvm-s3files/README.md
bfreiberg and others added 3 commits July 9, 2026 08:04
Review feedback (PR aws-samples#3206):
- README: title -> "AWS Lambda MicroVMs with Amazon S3 Files"
- README: make the VPC/subnet requirement prominent (supply OR create one),
  document that any subnet works (public or private) and why
- README: clarify stack outputs are informational; run.sh reads them by stack name
- README: document the AWS CLI minimum (v2.35.0+; lambda-microvms/s3files
  subcommands are missing on older builds)
- template: scope ConnectorOperatorRole ENI creation to the deployment's
  subnet + security group via resource ARNs. NOTE: the ec2:Vpc *condition key*
  does not work here (CreateNetworkConnector pre-validates the role without the
  VPC request context, so the connector fails to create); resource-ARN scoping
  is the validated equivalent.

Reliability fixes found while validating the README end-to-end in us-west-2:
- app.py: the /run hook reported mounted=true as soon as findmnt saw the mount,
  ~3s before the efs-proxy TLS tunnel could carry I/O, so a write issued right
  after `run` (e.g. `prove`) was silently lost. Add a bounded write/read/delete
  readiness probe and only report mounted once real I/O succeeds. Time-box the
  whole hook (~50s worst case) to stay under RunTimeoutInSeconds.
- run.sh: `run` now waits on the /run lifecycle event's mounted flag instead of
  the first HTTP 200, so the documented run -> prove flow can't race the mount.
- run.sh: pass the access-point root path as the run-payload prefix so the app
  reports correct s3:// locations (bucket + /microvm + file); prove() now polls
  for the exact object it wrote instead of any non-empty prefix.
- template: raise Run/Resume hook timeouts 30s -> 60s for the blocking mount.
- README/example-pattern: correct the cleanup sequence. The versioned data
  bucket blocks stack deletion; and because S3 Files keeps syncing (and flushes
  during teardown), empty the bucket AFTER the file system is gone: sam delete
  (fails on the bucket) -> empty the now-static bucket -> delete again. Use a
  guarded loop that also handles the already-empty case.
added lambda-microvm-s3files.json
@marcojahn

Copy link
Copy Markdown
Contributor

Hello @bfreiberg, thank you for your contribution. Your PR will be merged soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants