npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aws-cdk/aws-efs

v1.204.0

Published

The CDK Construct Library for AWS::EFS

Downloads

909,820

Readme

Amazon Elastic File System Construct Library


End-of-Support

AWS CDK v1 has reached End-of-Support on 2023-06-01. This package is no longer being updated, and users should migrate to AWS CDK v2.

For more information on how to migrate, see the Migrating to AWS CDK v2 guide.


Amazon Elastic File System (Amazon EFS) provides a simple, scalable, fully managed elastic NFS file system for use with AWS Cloud services and on-premises resources. Amazon EFS provides file storage in the AWS Cloud. With Amazon EFS, you can create a file system, mount the file system on an Amazon EC2 instance, and then read and write data to and from your file system.

This module is part of the AWS Cloud Development Kit project.

File Systems

Amazon EFS provides elastic, shared file storage that is POSIX-compliant. The file system you create supports concurrent read and write access from multiple Amazon EC2 instances and is accessible from all of the Availability Zones in the AWS Region where it is created. Learn more about EFS file systems

Create an Amazon EFS file system

A Virtual Private Cloud (VPC) is required to create an Amazon EFS file system. The following example creates a file system that is encrypted at rest, running in General Purpose performance mode, and Bursting throughput mode and does not transition files to the Infrequent Access (IA) storage class.

const fileSystem = new efs.FileSystem(this, 'MyEfsFileSystem', {
  vpc: new ec2.Vpc(this, 'VPC'),
  lifecyclePolicy: efs.LifecyclePolicy.AFTER_14_DAYS, // files are not transitioned to infrequent access (IA) storage by default
  performanceMode: efs.PerformanceMode.GENERAL_PURPOSE, // default
  outOfInfrequentAccessPolicy: efs.OutOfInfrequentAccessPolicy.AFTER_1_ACCESS, // files are not transitioned back from (infrequent access) IA to primary storage by default
});

⚠️ An Amazon EFS file system's performance mode can't be changed after the file system has been created. Updating this property will replace the file system.

Any file system that has been created outside the stack can be imported into your CDK app.

Use the fromFileSystemAttributes() API to import an existing file system. Here is an example of giving a role write permissions on a file system.

import * as iam from '@aws-cdk/aws-iam';

const importedFileSystem = efs.FileSystem.fromFileSystemAttributes(this, 'existingFS', {
  fileSystemId: 'fs-12345678', // You can also use fileSystemArn instead of fileSystemId.
  securityGroup: ec2.SecurityGroup.fromSecurityGroupId(this, 'SG', 'sg-123456789', {
    allowAllOutbound: false,
  }),
});

Permissions

If you need to grant file system permissions to another resource, you can use the .grant() API. As an example, the following code gives elasticfilesystem:ClientWrite permissions to an IAM role.

const role = new iam.Role(this, 'Role', {
  assumedBy: new iam.AnyPrincipal(),
});

fileSystem.grant(role, 'elasticfilesystem:ClientWrite');

Access Point

An access point is an application-specific view into an EFS file system that applies an operating system user and group, and a file system path, to any file system request made through the access point. The operating system user and group override any identity information provided by the NFS client. The file system path is exposed as the access point's root directory. Applications using the access point can only access data in its own directory and below. To learn more, see Mounting a File System Using EFS Access Points.

Use the addAccessPoint API to create an access point from a fileSystem.

fileSystem.addAccessPoint('AccessPoint');

By default, when you create an access point, the root(/) directory is exposed to the client connecting to the access point. You can specify a custom path with the path property.

If path does not exist, it will be created with the settings defined in the creationInfo. See Creating Access Points for more details.

Any access point that has been created outside the stack can be imported into your CDK app.

Use the fromAccessPointAttributes() API to import an existing access point.

efs.AccessPoint.fromAccessPointAttributes(this, 'ap', {
  accessPointId: 'fsap-1293c4d9832fo0912',
  fileSystem: efs.FileSystem.fromFileSystemAttributes(this, 'efs', {
    fileSystemId: 'fs-099d3e2f',
    securityGroup: ec2.SecurityGroup.fromSecurityGroupId(this, 'sg', 'sg-51530134'),
  }),
});

⚠️ Notice: When importing an Access Point using fromAccessPointAttributes(), you must make sure the mount targets are deployed and their lifecycle state is available. Otherwise, you may encounter the following error when deploying:

EFS file system <ARN of efs> referenced by access point <ARN of access point of EFS> has mount targets created in all availability zones the function will execute in, but not all are in the available life cycle state yet. Please wait for them to become available and try the request again.

Connecting

To control who can access the EFS, use the .connections attribute. EFS has a fixed default port, so you don't need to specify the port:

fileSystem.connections.allowDefaultPortFrom(instance);

Learn more about managing file system network accessibility

Mounting the file system using User Data

After you create a file system, you can create mount targets. Then you can mount the file system on EC2 instances, containers, and Lambda functions in your virtual private cloud (VPC).

The following example automatically mounts a file system during instance launch.

fileSystem.connections.allowDefaultPortFrom(instance);

instance.userData.addCommands("yum check-update -y",    // Ubuntu: apt-get -y update
  "yum upgrade -y",                                 // Ubuntu: apt-get -y upgrade
  "yum install -y amazon-efs-utils",                // Ubuntu: apt-get -y install amazon-efs-utils
  "yum install -y nfs-utils",                       // Ubuntu: apt-get -y install nfs-common
  "file_system_id_1=" + fileSystem.fileSystemId,
  "efs_mount_point_1=/mnt/efs/fs1",
  "mkdir -p \"${efs_mount_point_1}\"",
  "test -f \"/sbin/mount.efs\" && echo \"${file_system_id_1}:/ ${efs_mount_point_1} efs defaults,_netdev\" >> /etc/fstab || " +
  "echo \"${file_system_id_1}.efs." + Stack.of(this).region + ".amazonaws.com:/ ${efs_mount_point_1} nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport,_netdev 0 0\" >> /etc/fstab",
  "mount -a -t efs,nfs4 defaults");

Learn more about mounting EFS file systems

Deleting

Since file systems are stateful resources, by default the file system will not be deleted when your stack is deleted.

You can configure the file system to be destroyed on stack deletion by setting a removalPolicy

const fileSystem =  new efs.FileSystem(this, 'EfsFileSystem', {
  vpc: new ec2.Vpc(this, 'VPC'),
  removalPolicy: RemovalPolicy.DESTROY,
});