Nov 18, 20267 min read

S3 vs EFS: Object Storage or a Shared File System on AWS

How Amazon S3 and Amazon EFS differ in access model, consistency, latency and cost, which workloads need a POSIX file system, and which are better as objects behind an API.

Illustration for S3 vs EFS: Object Storage or a Shared File System on AWS

Amazon S3 and Amazon EFS both store files for applications on AWS, and they are reached in different ways. S3 is object storage behind an HTTPS API: you write a whole object under a key and read it back by key. EFS is a managed NFS file system: you mount it into EC2 instances, containers or Lambda functions, and every client sees the same directory tree with ordinary file operations.

The choice follows from how the software uses files. Code you write can call an API and treat files as immutable objects, which is what S3 is built for and priced for. Software that expects a path on disk, appends to logs, renames files into place or shares a working directory between processes needs a file system, and EFS is the managed one.

S3 vs EFS at a glance

Amazon S3Amazon EFS
AccessHTTPS API, SDKs, signed URLsNFSv4 mount on EC2, ECS, EKS and Lambda
ModelWhole objects by key, no in-place editsPOSIX files and directories, appends, renames, locks
ConsistencyStrong read-after-write for objectsFile system semantics across all clients
LatencyAn HTTPS round trip per requestSub-millisecond on EFS Standard for active data
Size limitsObjects up to 5 TBFile system grows and shrinks with use
Cost per GBLower, with cheaper classes for cold dataHigher, plus throughput and cross-AZ access charges
ReachAnywhere with credentials, including browsersClients in the VPC that can reach a mount target

When is S3 the better fit?

S3 fits when your code decides how files are read and written: user uploads, generated exports and reports, backups, media, data lake files and build artifacts. Objects up to 5 TB, strong read-after-write consistency, storage classes down to Glacier for cold data, lifecycle rules and signed URLs that let browsers upload and download directly all come with it. Nothing has to be mounted, so a service in another region or a client outside AWS can reach the same bucket.

The constraint is the object model. You cannot append to an object or edit part of it; you write a new version. Listing is by key prefix, not a directory tree, and renaming means copying. Every request is an HTTP round trip, so a workload that reads thousands of small files in a tight loop is slower than it would be on a file system.

When is EFS the better fit?

EFS fits software that needs a path: a CMS that writes uploads to a directory, a legacy application, a machine learning job that reads a shared dataset as files, or several containers that share a working directory. It is regional by default, storing data across Availability Zones, it can be mounted by ECS tasks, including Fargate, and Elastic Throughput scales with the workload without capacity planning.

The cost is higher per GB, and it grows in less obvious ways. EFS pricing adds charges for data read and written in Elastic Throughput mode, and accessing a mount target from another Availability Zone is billed at the EC2 cross-AZ rate in both directions. Clients must be inside the VPC, and a POSIX permission model with access points has to be designed alongside IAM.

How do you store files on S3 with Encore?

Encore

Encore is a backend framework with built-in infrastructure, and it covers the S3 side: an object storage bucket is a variable in your code, encore run gives you a local bucket, and a deploy creates an S3 bucket on AWS or a Cloud Storage bucket on GCP in your own account. Encore provisions an IAM role for the service. There is no EFS primitive, so a workload that needs a mounted file system stays outside Encore.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.

Set up the app

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

~
$ encore app create reports --example=hello-world$ cd reports && mkdir exports

Write exports as objects

A CSV export is the kind of file that belongs in S3: written once, read whole, downloaded by a browser. The endpoint streams rows straight into the object and returns a signed download URL valid for 15 minutes:

// Service exports writes CSV exports that users download later. package exports import ( "context" "encoding/csv" "fmt" "strconv" "time" "encore.dev/beta/auth" "encore.dev/storage/objects" ) // Private bucket: S3 on AWS, Cloud Storage on GCP, a local directory under encore run. var Exports = objects.NewBucket("exports", objects.BucketConfig{}) type ExportParams struct { Rows int `json:"rows"` } type ExportResponse struct { Key string `json:"key"` DownloadURL string `json:"download_url"` } //encore:api auth method=POST path=/exports func CreateExport(ctx context.Context, p *ExportParams) (*ExportResponse, error) { account, _ := auth.UserID() key := fmt.Sprintf("%s/%s.csv", string(account), time.Now().UTC().Format("20060102T150405Z")) // Stream rows into the object; nothing is buffered on local disk. w := Exports.Upload(ctx, key, objects.WithUploadAttrs(objects.UploadAttrs{ContentType: "text/csv"})) cw := csv.NewWriter(w) cw.Write([]string{"invoice_id", "amount_cents"}) for i := 1; i <= p.Rows; i++ { cw.Write([]string{fmt.Sprintf("inv_%d", i), strconv.Itoa(i * 100)}) } cw.Flush() if err := cw.Error(); err != nil { w.Abort(err) return nil, err } if err := w.Close(); err != nil { return nil, err } url, err := Exports.SignedDownloadURL(ctx, key, objects.WithTTL(15*time.Minute)) if err != nil { return nil, err } return &ExportResponse{Key: key, DownloadURL: url.URL}, nil } type ListResponse struct { Keys []string `json:"keys"` } //encore:api auth method=GET path=/exports func ListExports(ctx context.Context) (*ListResponse, error) { account, _ := auth.UserID() resp := &ListResponse{} for entry, err := range Exports.List(ctx, &objects.Query{Prefix: string(account) + "/"}) { if err != nil { return nil, err } resp.Keys = append(resp.Keys, entry.Name) } return resp, nil }

We ran this app with encore run: a three-row export returned a key and a signed URL, the URL served the CSV with its header and three rows, and listing the account's prefix returned the one key.

The bucket declaration is what the AWS deploy reads to create an S3 bucket with a unique name for each environment, and the code that writes to it does not change between local, staging and production.

Best fit: Application files your code reads and writes, such as uploads, exports and generated documents, in your own AWS or GCP account.

S3 and EFS by hand

For S3 by hand, you create the bucket, block public access, attach a lifecycle rule and give the task role s3:PutObject and s3:GetObject on the prefix the service uses. The code is the same shape as above with the AWS SDK.

EFS needs more pieces before a container can write a file: the file system, a mount target in each subnet your tasks run in, a security group that allows NFS on port 2049 from the tasks, an access point that pins the POSIX user and root directory, and a task definition that mounts it:

{ "family": "renderer", "volumes": [ { "name": "shared-assets", "efsVolumeConfiguration": { "fileSystemId": "fs-examplefilesystem", "transitEncryption": "ENABLED", "authorizationConfig": { "accessPointId": "fsap-exampleaccesspoint", "iam": "ENABLED" } } } ], "containerDefinitions": [ { "name": "renderer", "image": "123456789012.dkr.ecr.eu-central-1.amazonaws.com/renderer:latest", "mountPoints": [ { "sourceVolume": "shared-assets", "containerPath": "/mnt/assets", "readOnly": false } ] } ] }

The task role then needs elasticfilesystem:ClientMount and ClientWrite on the file system, since iam is enabled. The container sees an ordinary directory at /mnt/assets, which is the reason to use EFS: the application code needs no SDK.

Best fit: EFS for software that needs a shared POSIX directory; S3 by hand when you already manage buckets in Terraform.

How to choose

Use S3 for files your code controls and EFS for software that needs a path on disk, and do not put EFS under a workload that only ever writes whole files, since it costs more per GB and adds a VPC dependency. When both are needed, keep the shared working directory on EFS and move finished files to S3. Pick Encore for the S3 side when you want buckets and a local bucket to come from the code that uses them, deployed to your own AWS or GCP account.

Frequently asked questions

What is the difference between S3 and EFS?

S3 is object storage: you PUT and GET whole objects over HTTPS, by key, from anywhere with the right credentials. EFS is a managed NFS file system: you mount it on EC2, ECS, EKS or Lambda and use ordinary file operations, including appends, renames, locks and directories, shared by every client that mounts it.

Is EFS more expensive than S3?

Yes. Per GB stored, EFS Standard is billed at a higher rate than S3 Standard, and EFS also bills for throughput in Elastic mode and for cross-AZ access. EFS Infrequent Access and Archive classes narrow the gap for cold data. For files that are written once and read whole, S3 is usually the better fit.

When should you use EFS instead of S3?

When the software needs a file system path rather than an API: legacy applications, tools that append to or modify files in place, content management systems that keep uploads on disk, shared home directories, or several containers that need the same directory. If you control the code and files are written once, S3 is the better fit.

Does Encore support EFS?

No. Encore's object storage provisions S3 buckets on AWS and Cloud Storage buckets on GCP from a bucket declared in code, with a local bucket under encore run. A workload that needs a mounted file system needs EFS set up outside Encore.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders