EFS Filesystems



An EFS filesystem provides simple, scalable, and elastic file storage for your applications. It allows shared access to data using a traditional file permissions model and a hierarchical directory structure. Files stored in an EFS filesystem are persistent, meaning they remain available even if the container or Lambda function that created them is no longer running.

A single filesystem can be mounted by thousands of compute resources concurrently, including Lambda functions and container services. The filesystem is serverless, automatically growing and shrinking as you add and remove files, and you only pay for the storage you use.

Under the hood, Stacktape uses AWS Elastic File System (EFS).

When to use them

EFS filesystems are ideal for use cases that require shared file storage that can be accessed by multiple compute resources at the same time. Common use cases include:

  • Web serving and content management
  • Media and entertainment workflows
  • Home directories
  • Database backups
  • Container storage
  • Big data analytics

Advantages

  • Shared access: Can be mounted concurrently by thousands of containers and Lambda functions across multiple Availability Zones.
  • Standard file system interface: Uses the NFSv4 protocol, allowing for seamless integration with applications that expect a standard file system.
  • Serverless and elastic: Automatically scales storage capacity up or down.
  • Highly available and durable: Data is stored redundantly across multiple Availability Zones.
  • Performance: Delivers low, consistent latency and high throughput.
  • Encryption: Data is encrypted both in transit and at rest.

Disadvantages

  • Latency: While latency is low, it's generally higher than with block storage (EBS) due to the distributed nature of EFS.
  • Cost: Can be more expensive than object storage (S3) or block storage (EBS) for certain workloads.
  • Not optimal for lowest-latency needs: For applications that require the absolute lowest latency for a single instance, EBS might be a better choice.

Basic usage

resources:
  myFileSystem:
    type: efs-filesystem

Mounting to resources

You can mount a filesystem to a compute resource by specifying the volumeMounts property. Stacktape automatically handles the necessary network and IAM permissions.

resources:
  myEfsFilesystem:
    type: efs-filesystem

  myService:
    type: web-service
    properties:
      packaging:
        type: stacktape-image-buildpack
        properties:
          entryfilePath: src/server.ts
      resources:
        cpu: 0.25
        memory: 512
      volumeMounts:
        - type: efs
          properties:
            efsFilesystemName: myEfsFilesystem
            mountPath: /mnt/my-mounted-system

Mounting a filesystem to a web service.

You can then access the mounted directory just like any other directory in your compute resource's filesystem.

import * as fs from "fs";
import * as path from "path";

const mountPath = "/mnt/my-mounted-system";
const testFile = path.join(mountPath, "test.txt");

fs.writeFileSync(testFile, "Hello from EFS!");

const data = fs.readFileSync(testFile, "utf8");
// data is now "Hello from EFS!"

An example of writing to and reading from a mounted filesystem.

Throughput mode

You can set a throughput mode for your filesystem. While there are various options, the elastic mode (the default) is recommended for most use cases.

  • elastic (recommended): Auto-scales throughput. Best for spiky workloads (web apps, CI/CD).
  • provisioned: Fixed throughput you set via provisionedThroughputInMibps. Best for steady high-throughput workloads.
  • bursting: Throughput scales with storage size (50 KiB/s per GiB). Can run out of burst credits.
resources:
  myFileSystem:
    type: efs-filesystem
    properties:
      throughputMode: provisioned
      provisionedThroughputInMibps: 1000 # when setting throughput mode to 'provisioned', you must also set a throughput value

Backup

You can enable daily backups to protect your data against accidental deletion.

Enable daily automatic backups with 35-day retention. Incremental (only changes are copied).

resources:
  myFileSystem:
    type: efs-filesystem
    properties:
      backupEnabled: true

Limit access

You can limit a resource's access to a specific directory within the filesystem by specifying a rootDirectory.

Subdirectory within the EFS filesystem to mount. Omit for full access.

resources:
  myEfsFilesystem:
    type: efs-filesystem

  myFunction:
    type: function
    properties:
      packaging:
        type: stacktape-lambda-buildpack
        properties:
          entryfilePath: lambdas/read-write-efs.ts
      joinDefaultVpc: true
      volumeMounts:
        - type: efs
          properties:
            efsFilesystemName: myEfsFilesystem
            mountPath: /mnt/my-mounted-system
            rootDirectory: /my/root/directory

A Lambda function with limited access to a filesystem.