New serverless pattern - lambda-s3-files-cdk#3075
New serverless pattern - lambda-s3-files-cdk#3075NithinChandranR-AWS wants to merge 6 commits intoaws-samples:mainfrom
Conversation
Deploy a Lambda function with an Amazon S3 Files file system mounted as a local directory, enabling standard file operations on S3 data without downloading objects. Key features: - S3 Files FileSystem with NFS mount on Lambda at /mnt/s3data - VPC with 2 AZs, mount targets, and access point (L1 constructs) - Security group for NFS traffic (port 2049) - Read, write, and list operations via standard fs module - Bidirectional sync between S3 bucket and mounted filesystem - Sub-millisecond latency on actively used data
Replace wildcard resource with specific S3 Files access point ARN for least-privilege IAM.
|
Thanks for submitting this pattern! Here's what needs to be addressed:
|
|
|
||
| ## How it works | ||
|
|
||
| [Amazon S3 Files](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-files.html) (GA April 2026) provides NFS access to S3 buckets with full POSIX semantics. This pattern mounts an S3 bucket on a Lambda function at `/mnt/s3data`. |
There was a problem hiding this comment.
| [Amazon S3 Files](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-files.html) (GA April 2026) provides NFS access to S3 buckets with full POSIX semantics. This pattern mounts an S3 bucket on a Lambda function at `/mnt/s3data`. | |
| [Amazon S3 Files](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-files.html) provides NFS access to S3 buckets with full POSIX semantics. This pattern mounts an S3 bucket on a Lambda function at `/mnt/s3data`. |
|
|
||
| // Lambda function with S3 Files mount | ||
| const fn = new lambda.Function(this, "S3FilesFn", { | ||
| runtime: lambda.Runtime.NODEJS_22_X, |
There was a problem hiding this comment.
Why not use the latest runtime version?
There was a problem hiding this comment.
Upgraded to nodejs24.x via CDK escape hatch (L2 does not have NODEJS_24_X yet). Deployed and tested on a live stack — list, write, and read all pass. Fixed in f963437.
| @@ -0,0 +1,61 @@ | |||
| { | |||
| "title": "Lambda with Amazon S3 Files Mount", | |||
There was a problem hiding this comment.
| "title": "Lambda with Amazon S3 Files Mount", | |
| "title": "AWS Lambda with Amazon S3 Files Mount", |
There was a problem hiding this comment.
Updated to "AWS Lambda with Amazon S3 Files Mount". Fixed in f963437.
| "headline": "How it works", | ||
| "text": [ | ||
| "This pattern deploys a Lambda function with an Amazon S3 Files file system mounted at /mnt/s3data. The function performs standard file operations (read, write, list) on S3 data using the local filesystem — no S3 API calls needed.", | ||
| "S3 Files (GA April 2026) provides NFS access to S3 buckets with sub-millisecond latency on small files and full POSIX semantics. The pattern creates a VPC, S3 Files file system, mount targets, access point, and a Lambda function wired together.", |
There was a problem hiding this comment.
| "S3 Files (GA April 2026) provides NFS access to S3 buckets with sub-millisecond latency on small files and full POSIX semantics. The pattern creates a VPC, S3 Files file system, mount targets, access point, and a Lambda function wired together.", | |
| "S3 Files provides NFS access to S3 buckets with sub-millisecond latency on small files and full POSIX semantics. The pattern creates a VPC, S3 Files file system, mount targets, access point, and a Lambda function wired together.", |
There was a problem hiding this comment.
Applied suggested description, removed "(GA April 2026)". Fixed in f963437.
- Remove (GA April 2026) from README and example-pattern.json - Upgrade runtime to nodejs24.x via escape hatch - Update title to 'AWS Lambda with Amazon S3 Files Mount' - Use reviewer-suggested description text
|
Thanks for the quick review, @bfreiberg! All 4 comments addressed and pushed. Would appreciate another look when you get a chance |
| "aws-cdk-lib": "2.180.0", | ||
| "constructs": "10.4.2" |
There was a problem hiding this comment.
Could you please update these to the latest version. Please also use ^ to make them compatible with future releases
There was a problem hiding this comment.
Updated to aws-cdk-lib ^2.251.0 and constructs ^10.6.0. Fixed in 81c938c.
|
|
||
| // Attach S3 Files filesystem config via escape hatch | ||
| const cfnFn = fn.node.defaultChild as lambda.CfnFunction; | ||
| cfnFn.addOverride("Properties.Runtime", "nodejs24.x"); |
There was a problem hiding this comment.
the latest cdk version include NODEJS_24_X as a lambda.Runtime value
There was a problem hiding this comment.
Switched to lambda.Runtime.NODEJS_24_X — no more escape hatch. Fixed in 81c938c.
| // Attach S3 Files filesystem config via escape hatch | ||
| const cfnFn = fn.node.defaultChild as lambda.CfnFunction; | ||
| cfnFn.addOverride("Properties.Runtime", "nodejs24.x"); | ||
| cfnFn.fileSystemConfigs = [ |
There was a problem hiding this comment.
cdk 2.521.0 and higher support S3 Files directly: https://docs.aws.amazon.com/cdk/api/v2/java/software/amazon/awscdk/services/lambda/FileSystem.html
There was a problem hiding this comment.
Refactored to use typed s3files.CfnFileSystem/CfnMountTarget/CfnAccessPoint constructs and lambda.FileSystem.fromS3FilesAccessPoint(). Deployed and tested — write, read, list all pass. Fixed in 81c938c.
- Update aws-cdk-lib to ^2.251.0 and constructs to ^10.6.0 - Replace generic CfnResource with s3files.CfnFileSystem/CfnMountTarget/CfnAccessPoint - Use lambda.Runtime.NODEJS_24_X instead of escape hatch - Use lambda.FileSystem.fromS3FilesAccessPoint instead of manual fileSystemConfigs
…ame references - Add safePath() to validate filenames/directories against traversal attacks - Use 'AWS Lambda' and 'AWS IAM' for first references in README
|
All 3 items from the initial review addressed in e4464d7:
Deployed and tested on a live stack — normal operations pass, traversal attempts are blocked. |
bfreiberg
left a comment
There was a problem hiding this comment.
Looks good, thanks for your contribution. Your pattern will be merged to Serverlessland soon
New Serverless Pattern: Lambda with Amazon S3 Files Mount
Description
Deploys a Lambda function with an Amazon S3 Files file system mounted at
/mnt/s3data, enabling standard file operations (read, write, list) on S3 data without downloading objects. Uses Amazon S3 Files (GA April 2026).Architecture
Key Features
fsmoduleFramework / Language
Deployment & Testing
Files
lib/lambda-s3-files-stack.tssrc/index.jsexample-pattern.json