AWS CDK EFS Construct Library (v1)

1.204.0 · maintenance · verified Thu Apr 16

The AWS CDK Construct Library for AWS EFS (Amazon Elastic File System) provides constructs to create and manage EFS resources as infrastructure-as-code. This package is part of the AWS CDK v1 ecosystem (version 1.204.0), which is currently in maintenance mode. AWS CDK v1 typically sees infrequent updates, primarily for critical bug fixes or security patches.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create an AWS EFS File System within a new VPC, including an optional Access Point for POSIX-compliant access. It's designed for AWS CDK v1 projects. Remember to configure your AWS credentials and default region/account for `cdk deploy`.

import os
from aws_cdk import (
    core as cdk,
    aws_ec2 as ec2,
    aws_efs as efs,
)

class EfsStack(cdk.Stack):
    def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Create a VPC for the EFS File System
        vpc = ec2.Vpc(self, "EfsVpc", max_azs=2)

        # Create an EFS File System
        file_system = efs.FileSystem(self, "MyEfsFileSystem",
            vpc=vpc,
            performance_mode=efs.PerformanceMode.GENERAL_PURPOSE,
            throughput_mode=efs.ThroughputMode.BURSTING,
            encrypted=True
        )

        # Optional: Create an Access Point for granular access control
        efs.AccessPoint(self, "MyEfsAccessPoint",
            file_system=file_system,
            path="/mydata",
            create_acl=efs.Acl(owner_uid="1001", owner_gid="1001", permissions="755"),
            posix_user=efs.PosixUser(uid="1001", gid="1001")
        )

        cdk.CfnOutput(self, "FileSystemId", value=file_system.file_system_id)

app = cdk.App()
EfsStack(app, "EfsQuickstartStack",
         env=cdk.Environment(account=os.environ.get("CDK_DEFAULT_ACCOUNT", ""), 
                             region=os.environ.get("CDK_DEFAULT_REGION", ""))
)
app.synth()

view raw JSON →