Skip to content

FileSystem

Source: src/AWS/S3Files/FileSystem.ts

An Amazon S3 File System — POSIX-style file system access over an S3 general purpose bucket (mountable from EC2/ECS via mount targets, with application-scoped access via AccessPoints).

S3 Files is a newer service; availability varies by region and account.

Basic File System

import * as AWS from "alchemy/AWS";
// S3 Files requires versioning on the source bucket.
const bucket = yield* AWS.S3.Bucket("Data", { versioning: "Enabled" });
const role = yield* AWS.IAM.Role("FilesRole", {
assumeRolePolicyDocument: {
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
// S3 Files runs on EFS infrastructure and assumes the role as
// the elasticfilesystem service principal.
Principal: { Service: "elasticfilesystem.amazonaws.com" },
Action: ["sts:AssumeRole"],
},
],
},
inlinePolicies: {
bucket: {
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
Action: ["s3:ListBucket", "s3:ListBucketVersions"],
Resource: [bucket.bucketArn],
},
{
Effect: "Allow",
Action: ["s3:GetObject*", "s3:PutObject*", "s3:DeleteObject*", "s3:List*", "s3:AbortMultipartUpload"],
Resource: [AWS.Output.interpolate`${bucket.bucketArn}/*`],
},
],
},
},
});
const fs = yield* AWS.S3Files.FileSystem("Files", {
bucket: bucket.bucketArn,
roleArn: role.roleArn,
});

Prefix-Scoped File System

const fs = yield* AWS.S3Files.FileSystem("Files", {
bucket: bucket.bucketArn,
prefix: "shared/",
roleArn: role.roleArn,
});