aws-cdk-lib.aws_lambda.FileSystem

class FileSystem

LanguageType name
.NETAmazon.CDK.AWS.Lambda.FileSystem
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awslambda#FileSystem
Javasoftware.amazon.awscdk.services.lambda.FileSystem
Pythonaws_cdk.aws_lambda.FileSystem
TypeScript (source)aws-cdk-lib » aws_lambda » FileSystem

Represents the filesystem for the Lambda function.

Example

import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as efs from 'aws-cdk-lib/aws-efs';

// create a new VPC
const vpc = new ec2.Vpc(this, 'VPC');

// create a new Amazon EFS filesystem
const fileSystem = new efs.FileSystem(this, 'Efs', { vpc });

// create a new access point from the filesystem
const accessPoint = fileSystem.addAccessPoint('AccessPoint', {
  // set /export/lambda as the root of the access point
  path: '/export/lambda',
  // as /export/lambda does not exist in a new efs filesystem, the efs will create the directory with the following createAcl
  createAcl: {
    ownerUid: '1001',
    ownerGid: '1001',
    permissions: '750',
  },
  // enforce the POSIX identity so lambda function will access with this identity
  posixUser: {
    uid: '1001',
    gid: '1001',
  },
});

const fn = new lambda.Function(this, 'MyLambda', {
  // mount the access point to /mnt/msg in the lambda runtime environment
  filesystem: lambda.FileSystem.fromEfsAccessPoint(accessPoint, '/mnt/msg'),
  runtime: lambda.Runtime.NODEJS_18_X,
  handler: 'index.handler',
  code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
  vpc,
});

Initializer (protected)

super(config: FileSystemConfig)

Parameters

  • config FileSystemConfig — the FileSystem configurations for the Lambda function.

Properties

NameTypeDescription
configFileSystemConfigthe FileSystem configurations for the Lambda function.

config

Type: FileSystemConfig

the FileSystem configurations for the Lambda function.

Methods

NameDescription
static fromEfsAccessPoint(ap, mountPath)mount the filesystem from Amazon EFS.

static fromEfsAccessPoint(ap, mountPath)

public static fromEfsAccessPoint(ap: IAccessPoint, mountPath: string): FileSystem

Parameters

  • ap IAccessPoint — the Amazon EFS access point.
  • mountPath string — the target path in the lambda runtime environment.

Returns

  • FileSystem

mount the filesystem from Amazon EFS.