-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(lambda): circular dependencies when EFS and Lambda are deployed in separate stacks #28560
Conversation
…fix-efs-lambda-deploy-error
…fix-efs-lambda-deploy-error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for detailing out the issue and solution @sakurai-ryo, this will be another helpful win for the community!
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Pull request has been modified.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
This PR fixed an error when deploying EFS and Lambda in separate stacks.
Cause of the bug
Currently, when using EFS from Lambda, deploying EFS and Lambda in separate stacks creates incorrect resource dependencies and cannot be deployed correctly.
This error is caused by adding a security group setting in the Function construct to allow EFS and Lambda to communicate correctly.
By calling the
Connections.allowDefaultPortFrom
method of the Filesystem in the LambdaStack, IngressRule is created in the scope of the EfsStack.Note that the
remoteRule
flag is false when callingSecurityGroupBase.addIngressRule
at this time.aws-cdk/packages/aws-cdk-lib/aws-lambda/lib/function.ts
Line 1416 in dde5975
aws-cdk/packages/aws-cdk-lib/aws-ec2/lib/connections.ts
Line 157 in dde5975
aws-cdk/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts
Line 84 in dde5975
Here is the minimal code to reproduce this error without EFS and Lambda.
By calling the
SecurityGroupBase.addIngressRule
method with theremoteRule
flag true, the IngressRule will be deployed in the scope of the Lambda stack and the deployment will complete successfully.Changes
Fixed the SecurityGroup Rule configuration part in the Function construct to fix this error.
By changing the Function construct to call the
Connections.allowTo
method, theremoteRule
flag is set to true whenallowTo
method callsallowFrom
method and the EFS Security Group Ingress Rule will be correctly created in the scope of the Lambda stack.aws-cdk/packages/aws-cdk-lib/aws-ec2/lib/connections.ts
Line 139 in dde5975
aws-cdk/packages/aws-cdk-lib/aws-ec2/lib/connections.ts
Line 141 in dde5975
Closes #18759
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license