prefect-aws
The prefect-aws
integration makes it easy to leverage the capabilities of AWS in your workflows.
For example, you can retrieve secrets using AWS Secrets Manager, read and write objects with AWS S3, and deploy your flows on AWS ECS.
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.
Upgrade to the latest versions of prefect
and prefect-aws
:
Register newly installed block types
Register the block types in prefect-aws
to make them available for use.
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.
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.
Lambda
Invoke AWS Lambdas, synchronously or asynchronously.
Secret Manager
Create a block to read, write, and delete AWS Secret Manager secrets.
Run flows on AWS ECS
Run flows on AWS Elastic Container Service (ECS) to dynamically scale your infrastructure.
Prefect Cloud offers ECS push work pools. Push work pools submit runs directly to ECS, instead of requiring a worker to actively poll for flow runs to execute.
See the ECS work pool guide for a walkthrough of using ECS in a hybrid work pool.
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
For assistance using AWS, consult the AWS documentation and, in particular, the Boto3 documentation.
Refer to the prefect-aws
SDK documentation linked in the sidebar to explore all the capabilities of the prefect-aws
library.
Refer to the secrets documentation to see an example of using the AwsCredentials
block with a third-party service like Snowflake. The example does not require you to save your AWS credentials as part of the Snowflake block.
Was this page helpful?