MCPcopy Index your code
hub / github.com/zappa/Zappa / create_efs

Method create_efs

zappa/core.py:1028–1127  ·  view source on GitHub ↗

Create EFS file system, mount targets, and access point for Lambda. Returns the access point ARN.

(
        self,
        lambda_name: str,
        vpc_config: dict,
        mount_path: str = DEFAULT_EFS_MOUNT_POINT,
        throughput_mode: str = "bursting",
        performance_mode: str = "generalPurpose",
    )

Source from the content-addressed store, hash-verified

1026 ##
1027
1028 def create_efs(
1029 self,
1030 lambda_name: str,
1031 vpc_config: dict,
1032 mount_path: str = DEFAULT_EFS_MOUNT_POINT,
1033 throughput_mode: str = "bursting",
1034 performance_mode: str = "generalPurpose",
1035 ) -> str:
1036 """
1037 Create EFS file system, mount targets, and access point for Lambda.
1038 Returns the access point ARN.
1039 """
1040 # Generate unique name based on mount path (e.g., /mnt/data -> data, /mnt/ -> default)
1041 mount_suffix = mount_path.replace("/mnt/", "").rstrip("/") or "default"
1042 efs_name = f"{lambda_name}-efs-{mount_suffix}"
1043
1044 # Check if EFS already exists (by name tag)
1045 existing = self.efs_client.describe_file_systems()
1046 file_system_id = None
1047 for fs in existing["FileSystems"]:
1048 tags = {t["Key"]: t["Value"] for t in fs.get("Tags", [])}
1049 if tags.get("Name") == efs_name:
1050 file_system_id = fs["FileSystemId"]
1051 logger.info(f"Using existing EFS: {file_system_id}")
1052 break
1053
1054 if file_system_id is None:
1055 # Create new file system
1056 logger.info(f"Creating EFS file system: {efs_name}")
1057 response = self.efs_client.create_file_system(
1058 CreationToken=efs_name,
1059 PerformanceMode=performance_mode,
1060 ThroughputMode=throughput_mode,
1061 Encrypted=True,
1062 Tags=[
1063 {"Key": "Name", "Value": efs_name},
1064 {"Key": "CreatedBy", "Value": "Zappa"},
1065 ],
1066 )
1067 file_system_id = response["FileSystemId"]
1068
1069 # Wait for file system to be available
1070 while True:
1071 fs_response = self.efs_client.describe_file_systems(FileSystemId=file_system_id)
1072 if fs_response["FileSystems"][0]["LifeCycleState"] == "available":
1073 break
1074 time.sleep(5)
1075
1076 # Create mount targets for each subnet
1077 security_group_ids = vpc_config.get("SecurityGroupIds", [])
1078 for subnet_id in vpc_config.get("SubnetIds", []):
1079 try:
1080 self.efs_client.create_mount_target(
1081 FileSystemId=file_system_id,
1082 SubnetId=subnet_id,
1083 SecurityGroups=security_group_ids,
1084 )
1085 logger.info(f"Created mount target in subnet: {subnet_id}")

Callers 2

deployMethod · 0.80
updateMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected