[aws-efs] Cannot import an existing EFS Access Point to use with a lambda function
See original GitHub issueCannot use efs.AccessPoint.fromAccessPointId()
with lambda.FileSystem.fromEfsAccessPoint()
. the former returns an IAccessPoint
when the later expect an AccessPoint
. I think following the CDK guidelines, lambda.FileSystem.fromEfsAccessPoint()
should expect an IAccessPoint
, not an AccessPoint
.
Argument of type 'IAccessPoint' is not assignable to parameter of type 'AccessPoint'.
Reproduction Steps
filesystem: lambda.FileSystem.fromEfsAccessPoint(
efs.AccessPoint.fromAccessPointId(this, 'ap', props.ap.accessPointId),
'/mnt/efs',
),
What did you expect to happen?
I would expect the CDK to let me use an existing VPC, FileSytem and AccessPoint for my new Lambda function.
I would also expect the AccessPoint
class to provide a fromAccessPointAttributes()
method to import the data that would accept AccessPointId
and FileSystem
attributes.
What actually happened?
I was not able to import an existing AccessPoint
. I ended up creating a new AccessPoint
within the same stack as my lambda function.
Environment
- CLI Version : 1.66.0
- Framework Version: 1.66.0
- Node.js Version: 12.16.3
- OS : Linux Ubuntu 18
- Language (Version): TypeScript (3.8.3)
Other
I would expect to have a efs.AccessPoint.fromAccessPointAttributes()
to import an Access Point. The fromAccessPointId()
doesn’t actually import the FileSystem
and that’s an issue when using it in the lambda function.
Here is an example of how it would look like:
interface LambdaStackProps extends StackProps {
vpcId: string;
publicSubnetsId: string[];
privateSubnetIds: string[];
availabilityZones: string[];
efs: efs.IFileSystem;
ap: efs.IAccessPoint;
sg: ISecurityGroup;
}
class LambdaStack extends Stack {
fn: lambda.IFunction;
constructor(scope: Construct, id: string, props: LambdaStackProps) {
super(scope, id, props);
let vpc = Vpc.fromVpcAttributes(this, 'vpc', {
vpcId: props.vpcId,
availabilityZones: props.availabilityZones,
publicSubnetIds: props.publicSubnetsId,
privateSubnetIds: props.privateSubnetIds,
});
let fileSystem = lambda.FileSystem.fromEfsAccessPoint(
efs.AccessPoint.fromAccessPointAttributes(this, 'ap', {
accessPointId: props.ap.accessPointId,
fileSystem: efs.FileSystem.fromFileSystemAttributes(this, 'efs', {
fileSystemId: props.efs.fileSystemId,
securityGroup: SecurityGroup.fromSecurityGroupId(this, 'sg', props.sg.securityGroupId),
}),
}),
'/mnt/efs',
);
this.fn = new lambda.Function(this, 'lambda', {
runtime: lambda.Runtime.NODEJS_12_X,
code: lambda.Code.fromInline('exports.handler = function(event, ctx, cb) { return cb(null, "hi"); }'),
handler: 'index.handler',
vpc: vpc,
filesystem: fileSystem,
});
}
}
This is 🐛 Bug Report
- 👋 I may be able to implement the fix
- ⚠️ This fix might incur a breaking change
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top GitHub Comments
@hassanazharkhan There is an implementation in https://github.com/aws/aws-cdk/pull/10712/files to make it work. You could try using this if you really need to. Otherwise, I would just create a new
AccessPoint
until this issue is resolved.I created a Pull Request for this. I would be happy to get feedback on it. Happy to rework if needed.