question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[aws-efs] Cannot import an existing EFS Access Point to use with a lambda function

See original GitHub issue

Cannot 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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DaWyzcommented, Nov 11, 2020

@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.

1reaction
DaWyzcommented, Oct 6, 2020

I created a Pull Request for this. I would be happy to get feedback on it. Happy to rework if needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring file system access for Lambda functions
Configure your Lambda function to access a file system such as an Amazon EFS file ... EFS file system – The access point...
Read more >
How to use EFS (Elastic File System) with AWS Lambda
Welcome to this video tutorial on how to configure, mount & use EFS with a lambda function.---Support my work :---Patreon: ...
Read more >
Deploying large packages on AWS Lambda using EFS
AWS Lambda is quite convenient. It is really easy just deploy a function on the cloud, without having to worry about the setup....
Read more >
aws-cdk.aws-efs · PyPI
Use the fromAccessPointAttributes() API to import an existing access point. efs.AccessPoint.from_access_point_attributes(self, "ap", ...
Read more >
How to connect EFS disk to a Lambda function?
AWS added the possibility to attach Elastic File System (EFS) disks to Lambda functions. That opened... Tagged with serverless, aws, efs, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found