Skip to content

Efs

Reference doc for the `sst.aws.Efs` component.

The Efs component lets you add Amazon Elastic File System (EFS) to your app.

Create the file system

sst.config.ts
const vpc = new sst.aws.Vpc("MyVpc");
const efs = new sst.aws.Efs("MyEfs", { vpc });

This needs a VPC.

Attach it to a Lambda function

sst.config.ts
new sst.aws.Function("MyFunction", {
vpc,
handler: "lambda.handler",
volume: { efs, path: "/mnt/efs" }
});

This is now mounted at /mnt/efs in the Lambda function.

Attach it to a container

sst.config.ts
const cluster = new sst.aws.Cluster("MyCluster", { vpc });
cluster.addService("MyService", {
public: {
ports: [{ listen: "80/http" }],
},
volumes: [
{ efs, path: "/mnt/efs" }
]
});

Mounted at /mnt/efs in the container.


Cost

By default this component uses Regional (Multi-AZ) with Elastic Throughput. The pricing is pay-per-use.

  • For storage: $0.30 per GB per month
  • For reads: $0.03 per GB per month
  • For writes: $0.06 per GB per month

The above are rough estimates for us-east-1, check out the EFS pricing for more details.


Constructor

new Efs(name, args, opts?)

Parameters

EfsArgs

performance?

Type Input<general-purpose | max-io>

Default “general-purpose”

The performance mode for the EFS file system.

The max-io mode can support higher throughput, but with slightly higher latency. It’s recommended for larger workloads like data analysis or meadia processing.

Both the modes are priced the same, but general-purpose is recommended for most use cases.

{
performance: "max-io"
}

throughput?

Type Input<provisioned | bursting | elastic>

Default “elastic”

The throughput mode for the EFS file system.

The default elastic mode scales up or down based on the workload. However, if you know your access patterns, you can use provisioned to have a fixed throughput.

Or you can use bursting to scale with the amount of storage you’re using. It also supports bursting to higher levels for up to 12 hours per day.

{
throughput: "bursting"
}

transform?

Type Object

Transform how this component creates its underlying resources.

transform.accessPoint?

Type AccessPointArgs | (args: AccessPointArgs, opts: ComponentResourceOptions, name: string) => void

Transform the EFS access point.

transform.fileSystem?

Type FileSystemArgs | (args: FileSystemArgs, opts: ComponentResourceOptions, name: string) => void

Transform the EFS file system.

transform.securityGroup?

Type SecurityGroupArgs | (args: SecurityGroupArgs, opts: ComponentResourceOptions, name: string) => void

Transform the security group for the EFS mount targets.

vpc

Type Vpc | Input<Object>

The VPC to use for the EFS file system.

Create a VPC component.

const myVpc = new sst.aws.Vpc("MyVpc");

And pass it in.

{
vpc: myVpc
}

Or pass in a custom VPC configuration.

{
vpc: {
subnets: ["subnet-0db7376a7ad4db5fd ", "subnet-06fc7ee8319b2c0ce"]
}
}

vpc.id

Type Input<string>

The ID of the VPC.

vpc.subnets

Type Input<Input<string>[]>

A list of subnet IDs in the VPC to create the EFS mount targets in.

Properties

accessPoint

Type Output<string>

The ID of the EFS access point.

id

Type Output<string>

The ID of the EFS file system.

nodes

Type Object

The underlying resources this component creates.

nodes.accessPoint

Type Output<AccessPoint>

The Amazon EFS access point.

nodes.fileSystem

Type Output<FileSystem>

The Amazon EFS file system.

Methods

static get

Efs.get(name, fileSystemID, opts?)

Parameters

  • name string

    The name of the component.
  • fileSystemID Input<string>

    The ID of the existing EFS file system.
  • opts? ComponentResourceOptions

Returns Efs

Reference an existing EFS file system with the given file system ID. This is useful when you create a EFS file system in one stage and want to share it in another. It avoids having to create a new EFS file system in the other stage.

Imagine you create a EFS file system in the dev stage. And in your personal stage frank, instead of creating a new file system, you want to share the same file system from dev.

sst.config.ts
const efs = $app.stage === "frank"
? sst.aws.Efs.get("MyEfs", "app-dev-myefs")
: new sst.aws.Efs("MyEfs", { vpc });

Here app-dev-myefs is the ID of the file system created in the dev stage. You can find this by outputting the file system ID in the dev stage.

sst.config.ts
return {
id: efs.id
};