Skip to content
v2.276.0

PosixUser Struct ​

Represents the PosixUser.

Example ​

ts
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_LATEST,
  handler: 'index.handler',
  code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
  vpc,
});
python
import aws_cdk.aws_ec2 as ec2
import aws_cdk.aws_efs as efs


# create a new VPC
vpc = ec2.Vpc(self, "VPC")

# create a new Amazon EFS filesystem
file_system = efs.FileSystem(self, "Efs", vpc=vpc)

# create a new access point from the filesystem
access_point = file_system.add_access_point("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
    create_acl=efs.Acl(
        owner_uid="1001",
        owner_gid="1001",
        permissions="750"
    ),
    # enforce the POSIX identity so lambda function will access with this identity
    posix_user=efs.PosixUser(
        uid="1001",
        gid="1001"
    )
)

fn = lambda_.Function(self, "MyLambda",
    # mount the access point to /mnt/msg in the lambda runtime environment
    filesystem=lambda_.FileSystem.from_efs_access_point(access_point, "/mnt/msg"),
    runtime=lambda_.Runtime.NODEJS_LATEST,
    handler="index.handler",
    code=lambda_.Code.from_asset(path.join(__dirname, "lambda-handler")),
    vpc=vpc
)
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.efs.*;


// create a new VPC
Vpc vpc = new Vpc(this, "VPC");

// create a new Amazon EFS filesystem
FileSystem fileSystem = FileSystem.Builder.create(this, "Efs").vpc(vpc).build();

// create a new access point from the filesystem
AccessPoint accessPoint = fileSystem.addAccessPoint("AccessPoint", AccessPointOptions.builder()
        // 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(Acl.builder()
                .ownerUid("1001")
                .ownerGid("1001")
                .permissions("750")
                .build())
        // enforce the POSIX identity so lambda function will access with this identity
        .posixUser(PosixUser.builder()
                .uid("1001")
                .gid("1001")
                .build())
        .build());

Function fn = Function.Builder.create(this, "MyLambda")
        // mount the access point to /mnt/msg in the lambda runtime environment
        .filesystem(FileSystem.fromEfsAccessPoint(accessPoint, "/mnt/msg"))
        .runtime(Runtime.NODEJS_LATEST)
        .handler("index.handler")
        .code(Code.fromAsset(join(__dirname, "lambda-handler")))
        .vpc(vpc)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.EFS;


// create a new VPC
var vpc = new Vpc(this, "VPC");

// create a new Amazon EFS filesystem
var fileSystem = new FileSystem(this, "Efs", new FileSystemProps { Vpc = vpc });

// create a new access point from the filesystem
var accessPoint = fileSystem.AddAccessPoint("AccessPoint", new AccessPointOptions {
    // 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 = new Acl {
        OwnerUid = "1001",
        OwnerGid = "1001",
        Permissions = "750"
    },
    // enforce the POSIX identity so lambda function will access with this identity
    PosixUser = new PosixUser {
        Uid = "1001",
        Gid = "1001"
    }
});

var fn = new Function(this, "MyLambda", new FunctionProps {
    // mount the access point to /mnt/msg in the lambda runtime environment
    Filesystem = FileSystem.FromEfsAccessPoint(accessPoint, "/mnt/msg"),
    Runtime = Runtime.NODEJS_LATEST,
    Handler = "index.handler",
    Code = Code.FromAsset(Join(__dirname, "lambda-handler")),
    Vpc = vpc
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import efs "github.com/aws/aws-cdk-go/awscdk"


// create a new VPC
vpc := ec2.NewVpc(this, jsii.String("VPC"))

// create a new Amazon EFS filesystem
fileSystem := efs.NewFileSystem(this, jsii.String("Efs"), &FileSystemProps{
	Vpc: Vpc,
})

// create a new access point from the filesystem
accessPoint := fileSystem.AddAccessPoint(jsii.String("AccessPoint"), &AccessPointOptions{
	// set /export/lambda as the root of the access point
	Path: jsii.String("/export/lambda"),
	// as /export/lambda does not exist in a new efs filesystem, the efs will create the directory with the following createAcl
	CreateAcl: &Acl{
		OwnerUid: jsii.String("1001"),
		OwnerGid: jsii.String("1001"),
		Permissions: jsii.String("750"),
	},
	// enforce the POSIX identity so lambda function will access with this identity
	PosixUser: &PosixUser{
		Uid: jsii.String("1001"),
		Gid: jsii.String("1001"),
	},
})

fn := lambda.NewFunction(this, jsii.String("MyLambda"), &FunctionProps{
	// mount the access point to /mnt/msg in the lambda runtime environment
	Filesystem: lambda.FileSystem_FromEfsAccessPoint(accessPoint, jsii.String("/mnt/msg")),
	Runtime: lambda.Runtime_NODEJS_LATEST(),
	Handler: jsii.String("index.handler"),
	Code: lambda.Code_FromAsset(path.join(__dirname, jsii.String("lambda-handler"))),
	Vpc: Vpc,
})

Properties ​

gidstringgidstrgidStringGidstringGid*stringrequired#
The POSIX group ID used for all file system operations using this access point.
secondaryGidsoptionalstring[]secondary_gidsoptionaltyping.List[str]secondaryGidsoptionalList<String>SecondaryGidsoptionalstring[]SecondaryGidsoptional*[]*string= None#
Secondary POSIX group IDs used for all file system operations using this access point.
uidstringuidstruidStringUidstringUid*stringrequired#
The POSIX user ID used for all file system operations using this access point.