Skip to main content

Prefect collection of tasks and subflows to integrate with AWS

Project description

Coordinate and incorporate AWS in your dataflow with prefect-aws


PyPI

Visit the full docs here to see additional examples and the API reference.

Welcome!

prefect-aws is a collection of pre-built Prefect tasks that can be used to quickly construct Prefect flows that interact with Amazon Web Services.

Getting Started

Saving credentials to a block

You will need to obtain AWS credentials in order to use prefect-aws.

  1. Refer to the AWS Configuration documentation on how to retrieve your access key ID and secret access key
  2. Copy the access key ID and secret access key
  3. Create a short script, replacing the placeholders (or do so in the UI)
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
).save("BLOCK_NAME_PLACEHOLDER")

Congrats! You can now easily load the saved block, which holds your credentials:

from prefect_aws import AwsCredentials
AwsCredentials.load("BLOCK_NAME_PLACEHOLDER")

Write and run a flow

Upload and download from S3Bucket

from prefect import flow
from prefect_aws.s3 import S3Bucket

@flow
def example_flow():
    with open("hello.py", "w") as f:
        f.write("print('Hello world!')")

    s3_bucket = S3Bucket.load("my-bucket-test")
    s3_bucket.upload_from_path("hello.py")
    s3_bucket.download_object_to_path("hello.py", "downloaded_hello.py")

example_flow()

Write, read, and delete secret from AWS Secrets Manager

from prefect import flow
from prefect_aws import AwsCredentials, AwsSecret

@flow
def example_flow():
    secrets_manager = AwsSecret.load("my-block")
    secrets_manager.write_secret("my-secret-value")
    secret = secrets_manager.read_secret()
    print(secret)
    secrets_manager.delete_secret()

example_flow()

Use with_options to customize options on any existing task or flow

custom_example_flow = example_flow.with_options(
    name="My custom task name",
    retries=2,
    retry_delay_seconds=10,
) 

Resources

Refer to the API documentation on the sidebar to explore all the capabilities of Prefect AWS!

For more tips on how to use tasks and flows in a Collection, check out Using Collections!

Recipes

A tutorial on ECSTask can be found here.

For additional recipes and examples, check out prefect-recipes.

Feedback

If you have any questions or issues while using prefect-aws, you can find help in either the Prefect Discourse forum or the Prefect Slack community.

Feel free to star or watch prefect-aws for updates too!

Installation

Install prefect-aws

pip install prefect-aws

A list of available blocks in prefect-aws and their setup instructions can be found here.

Requires an installation of Python 3.7+

We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.

These tasks are designed to work with Prefect 2.0. For more information about how to use Prefect, please refer to the Prefect documentation.

Contributing

If you'd like to help contribute to fix an issue or add a feature to prefect-aws, please propose changes through a pull request from a fork of the repository.

Here are the steps:

  1. Fork the repository
  2. Clone the forked repository
  3. Install the repository and its dependencies:
pip install -e ".[dev]"
  1. Make desired changes
  2. Add tests
  3. Insert an entry to CHANGELOG.md
  4. Install pre-commit to perform quality checks prior to commit:
pre-commit install
  1. git commit, git push, and create a pull request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prefect-aws-0.2.5.tar.gz (73.0 kB view hashes)

Uploaded Source

Built Distribution

prefect_aws-0.2.5-py3-none-any.whl (39.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page