EFS¶
Utilities for working with Amazon Elastic File System.
Overview¶
| Module | Description |
|---|---|
| Core | Core EFS utilities |
| Mount Point | Mount point management |
| Paths | EFS path utilities |
MountPointConfiguration
dataclass
¶
MountPointConfiguration(
file_system, access_point, mount_point
)
Adapter for translating and mapping paths between AWS Elastic File System (EFS) mount points and local file system paths.
local file systems are most often used by: - EC2 instances - AWS Lambda functions
This class provides functionality to adapt file paths for applications that interact with AWS EFS. It allows for the conversion of paths from the EFS perspective to the local file system perspective and vice versa, considering the mount point and access point configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
file_system |
FileSystemDescriptionTypeDef
|
The description of the EFS file system. |
access_point |
Optional[AccessPointDescriptionTypeDef]
|
The description of the EFS access point, if used. |
mount_point |
Path
|
The local file system path where the EFS is mounted. |
access_point_path
property
¶
access_point_path
This is the access point on file system mounted to host
mount_point_path
property
¶
mount_point_path
This is the path on the host where the access point will be mounted
as_efs_path ¶
as_efs_path(path)
Converts a path to a path on the EFS file system.
Behavior: - If the path is absolute, the path is made relative to either the mount point or access point first. examples: - "/efs/accesspoint/path/to/file" -> "path/to/file" - "/mnt/efs/path/to/file" -> "path/to/file" - If the path is absolute and does not start with the mount point or access point, a ValueError is raised. - If the path is relative, It is assumed to be the relative path from the access point. e.g. "path/to/file" -> "/efs/accesspoint/path/to/file"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
StrPath
|
The path to convert to a path on the EFS file system. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
absolute path on the EFS file system. |
Source code in src/aibs_informatics_aws_utils/efs/mount_point.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
as_efs_uri ¶
as_efs_uri(path)
Converts a path to a customized URI EFSPath describing the location on an EFS file system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
StrPath
|
The path to convert to a path on the EFS file system. |
required |
Returns:
| Type | Description |
|---|---|
EFSPath
|
absolute URI path on the EFS file system. |
Source code in src/aibs_informatics_aws_utils/efs/mount_point.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
as_env_vars ¶
as_env_vars(name=None)
Converts the mount point configuration to environment variables.
Source code in src/aibs_informatics_aws_utils/efs/mount_point.py
237 238 239 240 241 242 243 244 | |
as_mounted_path ¶
as_mounted_path(path)
Converts a path to a path on the host where the EFS is mounted.
Behavior: - If the path is absolute, the path is made relative to either the mount point or access point first. examples: - "/efs/accesspoint/path/to/file" -> "path/to/file" - "/mnt/efs/path/to/file" -> "path/to/file" - If the path is absolute and does not start with the mount point or access point, a ValueError is raised. - If the path is relative, It is assumed to be the relative path from the mount point. e.g. "path/to/file" -> "/mnt/efs/path/to/file"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
StrPath
|
The path to convert to a path on the host where the EFS is mounted. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
absolute path on the host where the EFS is mounted. |
Source code in src/aibs_informatics_aws_utils/efs/mount_point.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
as_relative_path ¶
as_relative_path(path)
Converts a path to a relative path from the mount point or access point.
Behavior: - If the path is absolute and is relative to the mount point or access point, it is returned as a relative path. - If the path is already relative, it is returned as is. - If the path is absolute and is not relative to the mount point or access point, a ValueError is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
StrPath
|
The path to convert to a relative path. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The relative path. |
Source code in src/aibs_informatics_aws_utils/efs/mount_point.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
build
classmethod
¶
build(
mount_point,
access_point=None,
file_system=None,
access_point_tags=None,
file_system_tags=None,
)
Creates a new config from the given mount point and access point or file system.
Important: Must provide either access point or file system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mount_point
|
StrPath
|
Intended mount point of the EFS file system on the host. |
required |
access_point
|
Optional[Union[str, AccessPointDescriptionTypeDef]]
|
Identifier of the access point or the access point description. If specified as a string, can be either the access point id or name. Defaults to None. |
None
|
file_system
|
Optional[Union[str, FileSystemDescriptionTypeDef]]
|
Identifier of the file system or the file system description. If specified as a string, can be either the file system id or name. Defaults to None. |
None
|
access_point_tags
|
Optional[Dict[str, str]]
|
Tags to filter the access point. Defaults to None. |
None
|
file_system_tags
|
Optional[Dict[str, str]]
|
Tags to filter the file system. Defaults to None. |
None
|
Raises: ValueError: if neither access point nor file system is provided.
Returns:
| Type | Description |
|---|---|
MountPointConfiguration
|
The config |
Source code in src/aibs_informatics_aws_utils/efs/mount_point.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
is_efs_path ¶
is_efs_path(path)
Checks if the path is relative to the access point
Source code in src/aibs_informatics_aws_utils/efs/mount_point.py
229 230 231 | |
is_mounted_path ¶
is_mounted_path(path)
Checks if the path is relative to the mount point
Source code in src/aibs_informatics_aws_utils/efs/mount_point.py
233 234 235 | |
to_env_vars
classmethod
¶
to_env_vars(mount_point, mount_point_id, name=None)
Converts the mount point configuration to environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mount_point
|
StrPath
|
The mount point. |
required |
mount_point_id
|
Union[str, AccessPointId, FileSystemId]
|
The mount point identifier. |
required |
name
|
Optional[str]
|
Optional name for the mount point. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict[str, str]: The environment variables. |
Source code in src/aibs_informatics_aws_utils/efs/mount_point.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
translate_mounted_path ¶
translate_mounted_path(path, other)
Translates the location of a path described by another mount point to a location on this mount point
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
StrPath
|
The path to translate. should be relative path or absolute relative to the other mount point/access point. |
required |
other
|
T
|
The config of other mount point/access point to translate from. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If file system of other mount point/access point is not the same as this mount point/access point. |
Returns:
| Type | Description |
|---|---|
Path
|
The translated absolute path on this mount point. |
Source code in src/aibs_informatics_aws_utils/efs/mount_point.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
deduplicate_mount_points ¶
deduplicate_mount_points(mount_points)
Deduplicates a list of MountPointConfiguration objects based on the file system id and access point id.
Source code in src/aibs_informatics_aws_utils/efs/mount_point.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
get_efs_access_point ¶
get_efs_access_point(
access_point_id=None,
access_point_name=None,
access_point_tags=None,
file_system_id=None,
file_system_name=None,
file_system_tags=None,
)
Get EFS access point.
You can filter on id, name and tags for both access point and file system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_point_id
|
Optional[str]
|
Optionally filter on access point id. |
None
|
access_point_name
|
Optional[str]
|
Optionally filter on name. |
None
|
access_point_tags
|
Optional[Dict[str, str]]
|
Optionally filter on access point tags. They should be a dict of key-value pairs. |
None
|
file_system_id
|
Optional[str]
|
Optionally filter on file system id. |
None
|
file_system_name
|
Optional[str]
|
Optionally filter on file system name. |
None
|
file_system_tags
|
Optional[Dict[str, str]]
|
Optionally filter on file system tags. They should be a dict of key-value pairs. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no access point is found based on the filters. |
ValueError
|
If more than one access point is found based on the filters. |
Returns:
| Type | Description |
|---|---|
AccessPointDescriptionTypeDef
|
The access point description. |
Source code in src/aibs_informatics_aws_utils/efs/core.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
get_efs_file_system ¶
get_efs_file_system(
file_system_id=None, name=None, tags=None
)
Get EFS file system.
You can filter on id, name and tags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_system_id
|
Optional[str]
|
Optionally filter on file system id. |
None
|
name
|
Optional[str]
|
Optionally filter on name. |
None
|
tags
|
Optional[Dict[str, str]]
|
Optionally filter on tags. They should be a dict of key-value pairs. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no file system is found based on the filters. |
ValueError
|
If more than one file system is found based on the filters. |
Returns:
| Type | Description |
|---|---|
FileSystemDescriptionTypeDef
|
The file system description. |
Source code in src/aibs_informatics_aws_utils/efs/core.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
get_efs_path ¶
get_efs_path(
local_path: Path,
raise_if_unresolved: Literal[False],
mount_points: Optional[
List[MountPointConfiguration]
] = None,
) -> Optional[EFSPath]
get_efs_path(
local_path: Path,
raise_if_unresolved: Literal[True] = True,
mount_points: Optional[
List[MountPointConfiguration]
] = None,
) -> EFSPath
get_efs_path(
local_path, raise_if_unresolved=True, mount_points=None
)
Converts a local path assumed to be on a mount point to the EFS path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local_path
|
Path
|
Local path |
required |
raise_if_unresolved
|
bool
|
If True, raises an error if the local path is not under an identifiable mount point. Defaults to True. |
True
|
mount_points
|
List[MountPointConfiguration] | None
|
Optionally can override list of mount_points. If None, mount points are detected. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[EFSPath]
|
Corresponding EFS URI or None if the path cannot be resolved and raise_if_unresolved is False |
Source code in src/aibs_informatics_aws_utils/efs/paths.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
get_local_path ¶
get_local_path(
efs_path: EFSPath,
raise_if_unmounted: Literal[False],
mount_points: Optional[
List[MountPointConfiguration]
] = None,
) -> Optional[Path]
get_local_path(
efs_path: EFSPath,
raise_if_unmounted: Literal[True] = True,
mount_points: Optional[
List[MountPointConfiguration]
] = None,
) -> Path
get_local_path(
efs_path, raise_if_unmounted=True, mount_points=None
)
Gets a valid locally mounted path for the given EFS path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
efs_path
|
EFSPath
|
The EFS path. e.g., "efs://fs-12345678:/path/to/file.txt" |
required |
raise_if_unmounted
|
bool
|
If True, raises an error if the EFS path is not mounted locally. Defaults to True. |
True
|
mount_points
|
List[MountPointConfiguration] | None
|
Optionally can override list of mount points. If None, mount points are detected. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[Path]
|
The local path. e.g., "/mnt/efs/path/to/file.txt" or None if the path cannot be resolved and raise_if_unmounted is False |
Source code in src/aibs_informatics_aws_utils/efs/paths.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
list_efs_access_points ¶
list_efs_access_points(
access_point_id=None,
access_point_name=None,
access_point_tags=None,
file_system_id=None,
file_system_name=None,
file_system_tags=None,
)
List EFS access points.
You can filter on id, name and tags for both access point and file system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_point_id
|
Optional[str]
|
Optionally filter on access point id. |
None
|
access_point_name
|
Optional[str]
|
Optionally filter on name. |
None
|
access_point_tags
|
Optional[Dict[str, str]]
|
Optionally filter on access point tags. They should be a dict of key-value pairs. |
None
|
file_system_id
|
Optional[str]
|
Optionally filter on file system id. |
None
|
file_system_name
|
Optional[str]
|
Optionally filter on file system name. |
None
|
file_system_tags
|
Optional[Dict[str, str]]
|
Optionally filter on file system tags. They should be a dict of key-value pairs. |
None
|
Returns:
| Type | Description |
|---|---|
List[AccessPointDescriptionTypeDef]
|
List of matching access points |
Source code in src/aibs_informatics_aws_utils/efs/core.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
list_efs_file_systems ¶
list_efs_file_systems(
file_system_id=None, name=None, tags=None
)
List EFS file systems.
You can filter on id, name and tags.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_system_id
|
Optional[str]
|
Optionally filter on file system id. |
None
|
name
|
Optional[str]
|
Optionally filter on name. |
None
|
tags
|
Optional[Dict[str, str]]
|
Optionally filter on tags. They should be a dict of key-value pairs. |
None
|
Returns:
| Type | Description |
|---|---|
List[FileSystemDescriptionTypeDef]
|
List of matching file systems |
Source code in src/aibs_informatics_aws_utils/efs/core.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |