aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.57k stars 3.87k forks source link

(aws-efs): Support for attaching multile file systems to lambda function #14885

Open jessekrubin opened 3 years ago

jessekrubin commented 3 years ago

Support configuring multiple file systems as available in CFN: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-filesystemconfigs

Currently we can only specify one file system:

https://github.com/aws/aws-cdk/blob/8ed088a4cc5388b85776c3486cb657462836d923/packages/%40aws-cdk/aws-lambda/lib/function.ts#L280


Originaly reported as:

(aws-efs): unable to mount more than one efs with lambda function

I can mount multiple efs volumes manually for a lambda but using the ts-cdk library I cannot mount more than a single efs volume.

iliapolo commented 3 years ago

@jessekrubin We need some more information so we can properly investigate your scenario.

Can you please edit the issue according to our issue template?

Thanks

jessekrubin commented 3 years ago

@iliapolo Yes I can. sorry for the late reply. Was on vacation.

peterwoodworth commented 3 years ago

@jessekrubin are you still able to provide more information for this issue?

jessekrubin commented 3 years ago

I am working on recreating the issue in a simple repo.

jessekrubin commented 3 years ago

With the following cdk typescript app I see no way to add more than one efs mount. Any suggestions would be greatly appreciated.

import * as cdk from '@aws-cdk/core';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as efs from '@aws-cdk/aws-efs';
import * as lambda from '@aws-cdk/aws-lambda';
import * as apigw from '@aws-cdk/aws-apigateway';

export class CdkLambdaEfsStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    const vpc = new ec2.Vpc(this, 'Vpc', {
      maxAzs: 2, // Default is all AZs in the region
    });

    // Create a file system in EFS to store information
    const fs = new efs.FileSystem(this, 'FileSystem', {
      vpc,
      removalPolicy: cdk.RemovalPolicy.DESTROY
    });

    const accessPoint = fs.addAccessPoint('AccessPoint',{
      createAcl: {
        ownerGid: '1001',
        ownerUid: '1001',
        permissions: '750'
      },
      path:'/export/lambda',
      posixUser: {
        gid: '1001',
        uid: '1001'
      }
    });

    // defines an AWS Lambda resource
    const hello = new lambda.Function(this, 'HelloHandler', {
      runtime: lambda.Runtime.NODEJS_14_X,    // execution environment
      code: lambda.Code.fromAsset('lambda'),  // code loaded from "lambda" directory
      handler: 'hello.handler',               // file is "hello", function is "handler"
      vpc: vpc,
      filesystem: lambda.FileSystem.fromEfsAccessPoint(accessPoint, '/mnt/data')
    });

    // defines an API Gateway REST API resource backed by our "hello" function.
    new apigw.LambdaRestApi(this, 'Endpoint', {
      handler: hello
    });
  }
}
iliapolo commented 3 years ago

@jessekrubin Thanks for the details.

To my understanding, you are looking for a way to attach multiple file systems to a lambda function, similarly to how you can do this in CloudFormation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-filesystemconfigs

This is currently not supported by the L2 Function construct. I am repurposing this as a feature request and unassigning and marking this issue as p2, which means that we are unable to work on this immediately.

We use +1s to help prioritize our work, and are happy to revaluate this issue based on community feedback. You can reach out to the cdk.dev community on Slack to solicit support for reprioritization.

In the meantime, you can use Escape Hatches to directly change the underlying CFN resource definition and add more file system configurations.

github-actions[bot] commented 2 years ago

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

rprovodenko commented 2 years ago

Please implement this :)

madeline-k commented 1 year ago

From the cloudformation documentation, you can only specify a maximum of 1 FileSystemConfigs. This means it's not possible for us to support this (without a custom resource).

We should try to repro to verify that the documentation is accurate.

pavelrojkovtrepp commented 1 year ago

Please implement multiple EFS mounts support.

NathanZookCH commented 8 months ago

Welp, add me to the list of folks who want this. Right now, it looks like I have to use EC2.

aburgett87 commented 4 months ago

+1

saidalaoui-sq commented 3 months ago

+1

rbpartC commented 2 months ago

+1