Why use prefect-aws?
prefect-aws
offers significant advantages over direct boto3 integration:
- Production-ready integrations: Pre-built, tested components that handle common AWS patterns and edge cases
- Unified credential management: Secure, centralized authentication that works consistently across all AWS services
- Built-in observability: Automatic logging, monitoring, and state tracking for all AWS operations
- Infrastructure as code: Deploy and scale workflows on AWS ECS with minimal configuration
Getting started
Prerequisites
- An AWS account and the necessary permissions to access desired services.
Install prefect-aws
The following command will install a version ofprefect-aws
compatible with your installed version of prefect
. If you don’t already have prefect
installed, it will install the newest version of prefect
as well.
prefect
and prefect-aws
:
Blocks setup
Credentials
Most AWS services requires an authenticated session. Prefect makes it simple to provide credentials via AWS Credentials blocks. Steps:- Refer to the AWS Configuration documentation to retrieve your access key ID and secret access key.
- Copy the access key ID and secret access key.
- Create an
AwsCredentials
block in the Prefect UI or use a Python script like the one below.
S3
Create a block for reading and writing files to S3.Lambda
Invoke AWS Lambdas, synchronously or asynchronously.Secret Manager
Create a block to read, write, and delete AWS Secret Manager secrets.Supported AWS services
prefect-aws
provides comprehensive integrations for key AWS services:
Service | Integration Type | Use Cases |
---|---|---|
S3 | S3Bucket block | File storage, data lake operations, deployment storage |
Secrets Manager | AwsSecret block | Secure credential storage, API key management |
Lambda | LambdaFunction block | Serverless function execution, event-driven processing |
Glue | GlueJobBlock block | ETL operations, data transformation pipelines |
ECS | ECSWorker infrastructure | Container orchestration, scalable compute workloads |
Batch | batch_submit task | High-throughput computing, batch job processing |
- Blocks: Reusable configuration objects that can be saved and shared across flows
- Tasks: Functions decorated with
@task
for direct use in flows - Workers: Infrastructure components for running flows on AWS compute services
Scale workflows with AWS infrastructure
ECS (Elastic Container Service)
Deploy and scale your Prefect workflows on AWS ECS for production workloads.prefect-aws
provides:
- ECS worker: Long-running worker for hybrid deployments with full control over execution environment
- Auto-scaling: Dynamic resource allocation based on workflow demands
- Cost optimization: Pay only for compute resources when workflows are running
Docker Images
Pre-built Docker images withprefect-aws
are available for simplified deployment:
Available Tags
Image tags have the following format:prefecthq/prefect-aws:latest
- Latest stable release with Python 3.12prefecthq/prefect-aws:latest-python3.11
- Latest stable with Python 3.11prefecthq/prefect-aws:0.5.9-python3.12
- Specific prefect-aws version with Python 3.12prefecthq/prefect-aws:0.5.9-python3.12-prefect3.4.9
- Full version specification
Usage Examples
Running an ECS worker:Examples
Read and write files to AWS S3
Upload a file to an AWS S3 bucket and download the same file under a different filename. The following code assumes that the bucket already exists:Access secrets with AWS Secrets Manager
Write a secret to AWS Secrets Manager, read the secret data, delete the secret, and return the secret data.Invoke lambdas
Submit AWS Glue jobs
Submit AWS Batch jobs
Resources
Documentation
- prefect-aws SDK Reference - Complete API documentation for all blocks and tasks
- ECS Deployment Guide - Step-by-step guide for deploying workflows on ECS
- Prefect Secrets Management - Using AWS credentials with third-party services
AWS Resources
- AWS Documentation - Official AWS service documentation
- Boto3 Documentation - Python SDK reference for AWS services
- AWS IAM Best Practices - Security recommendations for AWS access