Skip to content

feat: add pass-through file_system_config variable for EFS support#181

Open
BrandonLWhite wants to merge 4 commits intomoritzzimmer:mainfrom
BrandonLWhite:file-system-config
Open

feat: add pass-through file_system_config variable for EFS support#181
BrandonLWhite wants to merge 4 commits intomoritzzimmer:mainfrom
BrandonLWhite:file-system-config

Conversation

@BrandonLWhite
Copy link
Contributor

This pull request adds support for configuring AWS Lambda functions with an Amazon EFS (Elastic File System) file system. The changes introduce a new variable for file system configuration and update the Lambda resource definitions to utilize this configuration if provided.

Support for EFS file system configuration:

  • Added a new file_system_config variable in variables.tf to allow specifying EFS connection settings, including the EFS ARN and local mount path.
  • Updated the documentation in README.md to describe the new file_system_config input and its requirements.

Resource updates to support EFS:

  • Modified the aws_lambda_function.lambda resource in main.tf to dynamically include the file_system_config block if the variable is set.
  • Modified the aws_lambda_function.lambda_external_lifecycle resource in main.tf to also support the dynamic inclusion of the file_system_config block.

Copilot AI review requested due to automatic review settings February 25, 2026 17:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for AWS Lambda functions to mount Amazon EFS (Elastic File System) by introducing a new file_system_config variable. This allows users to configure Lambda functions with EFS access points for persistent file storage, expanding the module's capabilities to support stateful Lambda workloads.

Changes:

  • Added a new optional file_system_config variable for configuring EFS Access Point connections
  • Updated both Lambda function resources (lambda and lambda_external_lifecycle) to support the EFS configuration using dynamic blocks
  • Added documentation for the new variable in the README

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
variables.tf Defines the new file_system_config variable with arn and local_mount_path fields, following the nullable object pattern used for other optional Lambda configurations
main.tf Adds dynamic file_system_config blocks to both Lambda function resources, consistently placed after environment configuration and using the standard null-check pattern
README.md Documents the new input variable in the inputs table with type information and usage guidance

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 78 to 85
variable "file_system_config" {
description = "Connection settings for an EFS file system. Before creating or updating Lambda functions with `file_system_config`, EFS mount targets must be in available lifecycle state. Use `depends_on` to explicitly declare this dependency. See [Amazon EFS for Lambda](https://docs.aws.amazon.com/lambda/latest/dg/services-efs.html) for more details."
default = null
type = object({
arn = string
local_mount_path = string
})
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding automatic IAM permissions for EFS access to maintain consistency with the module's pattern. The module automatically adds IAM policies for other features like VPC (AWSLambdaENIManagementAccess at iam.tf:25-30) and tracing (AWSXRayDaemonWriteAccess at iam.tf:32-37).

For EFS, the Lambda function needs elasticfilesystem:ClientMount and elasticfilesystem:ClientWrite permissions. While users can configure these separately, adding them automatically would align with the module's convention and improve user experience. You could create a custom IAM policy scoped to the EFS access point ARN provided in the variable, or document in the variable description that users must manually configure these IAM permissions.

Copilot uses AI. Check for mistakes.
variables.tf Outdated
}

variable "file_system_config" {
description = "Connection settings for an EFS file system. Before creating or updating Lambda functions with `file_system_config`, EFS mount targets must be in available lifecycle state. Use `depends_on` to explicitly declare this dependency. See [Amazon EFS for Lambda](https://docs.aws.amazon.com/lambda/latest/dg/services-efs.html) for more details."
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable description should mention that local_mount_path must start with /mnt/ as per AWS Lambda requirements. This is a constraint enforced by AWS Lambda and documenting it here would help users avoid configuration errors. Consider adding this detail to the description, for example: "The local_mount_path must start with /mnt/."

Suggested change
description = "Connection settings for an EFS file system. Before creating or updating Lambda functions with `file_system_config`, EFS mount targets must be in available lifecycle state. Use `depends_on` to explicitly declare this dependency. See [Amazon EFS for Lambda](https://docs.aws.amazon.com/lambda/latest/dg/services-efs.html) for more details."
description = "Connection settings for an EFS file system. Before creating or updating Lambda functions with `file_system_config`, EFS mount targets must be in available lifecycle state. Use `depends_on` to explicitly declare this dependency. See [Amazon EFS for Lambda](https://docs.aws.amazon.com/lambda/latest/dg/services-efs.html) for more details. The `local_mount_path` must start with `/mnt/`."

Copilot uses AI. Check for mistakes.
variables.tf Outdated
}

variable "file_system_config" {
description = "Connection settings for an EFS file system. Before creating or updating Lambda functions with `file_system_config`, EFS mount targets must be in available lifecycle state. Use `depends_on` to explicitly declare this dependency. See [Amazon EFS for Lambda](https://docs.aws.amazon.com/lambda/latest/dg/services-efs.html) for more details."
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation should mention that VPC configuration is required when using EFS. AWS Lambda functions must be configured with VPC access to connect to EFS file systems. Consider adding a note to the description such as: "Note: Lambda functions using EFS must be configured with vpc_config to access the file system within your VPC."

Suggested change
description = "Connection settings for an EFS file system. Before creating or updating Lambda functions with `file_system_config`, EFS mount targets must be in available lifecycle state. Use `depends_on` to explicitly declare this dependency. See [Amazon EFS for Lambda](https://docs.aws.amazon.com/lambda/latest/dg/services-efs.html) for more details."
description = "Connection settings for an EFS file system. Before creating or updating Lambda functions with `file_system_config`, EFS mount targets must be in available lifecycle state. Use `depends_on` to explicitly declare this dependency. Note: Lambda functions using EFS must be configured with `vpc_config` to access the file system within your VPC. See [Amazon EFS for Lambda](https://docs.aws.amazon.com/lambda/latest/dg/services-efs.html) for more details."

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 25, 2026 17:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

README.md Outdated
| <a name="input_description"></a> [description](#input\_description) | Description of what your Lambda Function does. | `string` | `"Instruction set architecture for your Lambda function. Valid values are [\"x86_64\"] and [\"arm64\"]."` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Environment (e.g. env variables) configuration for the Lambda function enable you to dynamically pass settings to your function code and libraries | <pre>object({<br> variables = map(string)<br> })</pre> | `null` | no |
| <a name="input_event_source_mappings"></a> [event\_source\_mappings](#input\_event\_source\_mappings) | Creates event source mappings to allow the Lambda function to get events from Kinesis, DynamoDB and SQS. The IAM role of this Lambda function will be enhanced with necessary minimum permissions to get those events. | `any` | `{}` | no |
| <a name="input_file_system_config"></a> [file\_system\_config](#input\_file\_system\_config) | Connection settings for an EFS file system. Before creating or updating Lambda functions with `file_system_config`, EFS mount targets must be in available lifecycle state. Use `depends_on` to explicitly declare this dependency. See [Amazon EFS for Lambda](https://docs.aws.amazon.com/lambda/latest/dg/services-efs.html) for more details. | <pre>object({<br> arn = string<br> local_mount_path = string<br> })</pre> | `null` | no |
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a discrepancy between the documentation in variables.tf and README.md. The variable description in variables.tf (line 79) states "Connection settings for an EFS Access Point" and specifies the ARN format must be an access point ARN, but the README.md description (line 390) more generically says "Connection settings for an EFS file system". These should be consistent. The variables.tf description is more accurate since the arn field must specifically be an EFS Access Point ARN, not just any EFS ARN.

Copilot uses AI. Check for mistakes.
Comment on lines +78 to +84
variable "file_system_config" {
description = "Connection settings for an EFS Access Point. The `arn` must be an EFS Access Point ARN (format: `arn:aws:elasticfilesystem:region:account-id:access-point/fsap-xxxxxxxxx`). Before creating or updating Lambda functions with `file_system_config`, EFS mount targets must be in available lifecycle state. Use `depends_on` to explicitly declare this dependency. See [Amazon EFS for Lambda](https://docs.aws.amazon.com/lambda/latest/dg/services-efs.html) for more details."
default = null
type = object({
arn = string
local_mount_path = string
})
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lambda functions using EFS file systems must be configured with VPC settings. Consider adding validation or documentation that explicitly states file_system_config requires vpc_config to be set. Currently, the variable description mentions the dependency on EFS mount targets but doesn't mention the VPC requirement, which could lead to runtime errors.

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +51
dynamic "file_system_config" {
for_each = var.file_system_config == null ? [] : [var.file_system_config]
content {
arn = file_system_config.value.arn
local_mount_path = file_system_config.value.local_mount_path
}
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the pattern established in iam.tf where vpc_config automatically adds necessary IAM permissions (lines 25-30), the file_system_config feature should also automatically grant required EFS permissions. Lambda functions need elasticfilesystem:ClientMount and potentially elasticfilesystem:ClientWrite permissions on the EFS access point ARN. Consider adding an aws_iam_role_policy_attachment resource in iam.tf that conditionally attaches when file_system_config is not null, similar to how vpc_attachment works.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings February 25, 2026 23:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

type = object({
arn = string
local_mount_path = string
})
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When file_system_config is set, Lambda/EFS has hard prerequisites (VPC config and a /mnt/... mount path). Consider adding validation blocks here to fail fast: require var.vpc_config to be non-null (and ideally have non-empty subnet_ids/security_group_ids), require local_mount_path to start with /mnt/, and optionally validate that arn looks like an EFS access point ARN (contains :access-point/).

Suggested change
})
})
validation {
condition = (
var.file_system_config == null ||
can(regex("^/mnt(/.*)?$", var.file_system_config.local_mount_path))
)
error_message = "When set, file_system_config.local_mount_path must be under /mnt (for example, /mnt/efs)."
}
validation {
condition = (
var.file_system_config == null ||
can(contains(var.file_system_config.arn, ":access-point/"))
)
error_message = "When set, file_system_config.arn must be an EFS access point ARN (it should contain ':access-point/')."
}

Copilot uses AI. Check for mistakes.
Comment on lines +48 to +53
dynamic "file_system_config" {
for_each = var.file_system_config == null ? [] : [var.file_system_config]
content {
arn = file_system_config.value.arn
local_mount_path = file_system_config.value.local_mount_path
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the file_system_config block alone isn’t sufficient for working EFS mounts: the Lambda execution role also needs EFS client permissions (e.g., elasticfilesystem:ClientMount/ClientWrite/ClientRootAccess on the access point), and EFS requires the function to be attached to a VPC. Since this module already manages IAM permissions for other optional features, consider extending it to add the required EFS permissions (gated on var.file_system_config != null) and/or enforcing the VPC prerequisite via variable validation.

Copilot uses AI. Check for mistakes.
| <a name="input_environment"></a> [environment](#input\_environment) | Environment (e.g. env variables) configuration for the Lambda function enable you to dynamically pass settings to your function code and libraries | <pre>object({<br/> variables = map(string)<br/> })</pre> | `null` | no |
| <a name="input_ephemeral_storage_size"></a> [ephemeral\_storage\_size](#input\_ephemeral\_storage\_size) | The size of your Lambda functions ephemeral storage (/tmp) represented in MB. Valid value between 512 MB to 10240 MB. | `number` | `512` | no |
| <a name="input_event_source_mappings"></a> [event\_source\_mappings](#input\_event\_source\_mappings) | Creates event source mappings to allow the Lambda function to get events from Kinesis, DynamoDB and SQS. The IAM role of this Lambda function will be enhanced with necessary minimum permissions to get those events. | `any` | `{}` | no |
| <a name="input_file_system_config"></a> [file\_system\_config](#input\_file\_system\_config) | Connection settings for an EFS Access Point. The `arn` must be an EFS Access Point ARN (format: `arn:aws:elasticfilesystem:region:account-id:access-point/fsap-xxxxxxxxx`). Before creating or updating Lambda functions with `file_system_config`, EFS mount targets must be in available lifecycle state. Use `depends_on` to explicitly declare this dependency. See [Amazon EFS for Lambda](https://docs.aws.amazon.com/lambda/latest/dg/services-efs.html) for more details. | <pre>object({<br/> arn = string<br/> local_mount_path = string<br/> })</pre> | `null` | no |
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs for file_system_config should call out the key prerequisites to avoid confusing apply/runtime failures: Lambda must be configured with vpc_config, the role needs EFS client permissions for the access point, and local_mount_path must start with /mnt/. Right now the row implies configuration-only support without mentioning these required additional inputs/permissions.

Copilot uses AI. Check for mistakes.
Copy link
Owner

@moritzzimmer moritzzimmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the PR @BrandonLWhite. Could please also add a new example (like with-efs) to test this functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants