Anish S
07/16/2025, 3:49 PMMarvin
07/16/2025, 3:49 PMMarvin
07/16/2025, 3:49 PMECSTask
configuration in Prefect:
python
from prefect_aws import ECSTask
from prefect.filesystems import RemoteFileSystem
ecs_task = ECSTask(
task_definition={
"family": "prefect-flow-with-efs",
"volumes": [{
"name": "efs-volume",
"efsVolumeConfiguration": {
"fileSystemId": "fs-xxxxxx", # Your EFS filesystem ID
"transitEncryption": "ENABLED",
"authorizationConfig": {
"iam": "ENABLED"
}
}
}],
"containerDefinitions": [{
"name": "flow-container",
"mountPoints": [{
"sourceVolume": "efs-volume",
"containerPath": "/mnt/efs", # Path where EFS will be mounted in container
"readOnly": False
}]
}]
}
)
2. When deploying your flow, use this ECS task configuration:
python
from prefect import flow
@flow
def my_flow_with_efs():
# Your flow code here
# The EFS volume will be available at /mnt/efs inside the container
with open("/mnt/efs/my_file.txt", "w") as f:
f.write("Hello from Prefect!")
# Deploy the flow
if __name__ == "__main__":
my_flow_with_efs.from_source(
source="your-source", # e.g., GitHub repository
infrastructure=ecs_task
).deploy(name="flow-with-efs")
Important considerations:
1. Prerequisites:
- An existing EFS filesystem in your AWS account
- Proper IAM roles and security groups configured
- Network configuration that allows your ECS tasks to access the EFS filesystem
2. Security:
- Ensure your ECS task role has appropriate permissions to access the EFS filesystem
- Configure security groups to allow NFS traffic (port 2049) between ECS and EFS
- Consider using encryption in transit as shown in the example
3. Performance:
- EFS access patterns can affect performance, so consider your use case
- For better performance, ensure your ECS tasks are in the same AZ as your EFS mount targets
4. Cost Considerations:
- Remember that EFS charges based on storage used and throughput
- Consider using EFS lifecycle management for cost optimization
The configuration above sets up a persistent EFS volume that will be available to your flow's container at the specified mount point (/mnt/efs
in the example). Any data written to this path will persist across flow runs and be available to other tasks that mount the same EFS volume.
For more detailed information about ECS configuration with Prefect, you can refer to the Prefect AWS ECS guide.
Would you like me to elaborate on any particular aspect of this setup, such as security configurations or performance optimization?