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
paulhcsun
left a comment
There was a problem hiding this comment.
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.allowDefaultPortFrommethod of the Filesystem in the LambdaStack, IngressRule is created in the scope of the EfsStack.Note that the
remoteRuleflag is false when callingSecurityGroupBase.addIngressRuleat 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.addIngressRulemethod with theremoteRuleflag 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.allowTomethod, theremoteRuleflag is set to true whenallowTomethod callsallowFrommethod 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