Build production-ready data workflows that seamlessly integrate with AWS services. prefect-aws provides battle-tested blocks, tasks, and infrastructure integrations for AWS, featuring support for ECS, S3, Secrets Manager, Lambda, Batch, and Glue.
Why use prefect-aws?
While you could integrate with AWS services directly using boto3, prefect-aws offers significant advantages:
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 in your workflows
Infrastructure as code: Deploy and scale your workflows on AWS ECS with minimal configuration
Error handling & retries: Robust error handling with intelligent retry logic for transient AWS service issues
Type safety: Full type hints and validation for all AWS service interactions
Getting started
Prerequisites
An AWS account and the necessary permissions to access desired services.
Installation
Install prefect-aws as a dependency of Prefect. If you don't already have prefect installed, it will install the newest version of prefect as well.
pip install "prefect[aws]"
Blocks setup
Credentials
Most AWS services require an authenticated session.
Prefect makes it simple to provide credentials via AWS Credentials blocks.
Create an AwsCredentials block in the Prefect UI or use a Python script like the one below.
from prefect_aws import AwsCredentials
AwsCredentials(
aws_access_key_id="PLACEHOLDER",
aws_secret_access_key="PLACEHOLDER",
aws_session_token=None, # replace this with token if necessary
region_name="us-east-2"
).save("BLOCK-NAME-PLACEHOLDER")
Prefect uses the Boto3 library under the hood.
To find credentials for authentication, any data not provided to the block are sourced at runtime in the order shown in the Boto3 docs.
Prefect creates the session object using the values in the block and then, any missing values follow the sequence in the Boto3 docs.
S3
Create a block for reading and writing files to S3.
from prefect_aws import AwsCredentials
from prefect_aws.s3 import S3Bucket
S3Bucket(
bucket_name="BUCKET-NAME-PLACEHOLDER",
credentials=aws_credentials
).save("S3-BLOCK-NAME-PLACEHOLDER")
Lambda
Invoke AWS Lambdas, synchronously or asynchronously.
from prefect_aws.lambda_function import LambdaFunction
from prefect_aws.credentials import AwsCredentials
LambdaFunction(
function_name="test_lambda_function",
aws_credentials=credentials,
).save("LAMBDA-BLOCK-NAME-PLACEHOLDER")
Secret Manager
Create a block to read, write, and delete AWS Secret Manager secrets.
from prefect_aws import AwsCredentials
from prefect_aws.secrets_manager import AwsSecret
AwsSecret(
secret_name="test_secret_name",
aws_credentials=credentials,
).save("AWS-SECRET-BLOCK-NAME-PLACEHOLDER")
RDS IAM Authentication (Experimental)
prefect-aws includes a plugin to automatically handle authentication for AWS RDS PostgreSQL databases using IAM tokens.
Prerequisites
Before using RDS IAM authentication, you need to configure AWS:
Enable IAM authentication on your RDS instance: In the AWS Console, modify your RDS instance and enable "IAM database authentication".
Create an IAM policy with the rds-db:connect permission: