AWS EFS
Mount an EFS file system to a function and a container.
This allows both your function and the container to access the same file system. Here they both update a counter that’s stored in the file system.
await writeFile("/mnt/efs/counter", newValue.toString());The file system is mounted to /mnt/efs in both the function and the container.
// NAT Gateways are required for Lambda functionsconst vpc = new sst.aws.Vpc("MyVpc", { nat: "managed" });
// Create an EFS file system to store a counterconst efs = new sst.aws.Efs("MyEfs", { vpc });
// Create a Lambda function that increments the counternew sst.aws.Function("MyFunction", { handler: "lambda.handler", url: true, vpc, volume: { efs, path: "/mnt/efs", },});
// Create a service that increments the same counterconst cluster = new sst.aws.Cluster("MyCluster", { vpc });new sst.aws.Service("MyService", { cluster, loadBalancer: { ports: [{ listen: "80/http" }], }, volumes: [ { efs, path: "/mnt/efs", }, ],});import { increment } from "./common.mjs";
export const handler = async () => { const counter = await increment(); console.log("COUNTER", counter); return { statusCode: 200, body: JSON.stringify({ counter, }), };};View the full example.