Amazon S3 Operators¶
Airflow to Amazon Simple Storage Service (S3) integration provides several operators to create and interact with S3 buckets.
Prerequisite Tasks¶
To use these operators, you must do a few things:
Create necessary resources using AWS Console or AWS CLI.
Install API libraries via pip.
pip install 'apache-airflow[amazon]'
Detailed information is available Installation
Create an Amazon S3 Bucket¶
To create an Amazon S3 bucket you can use
S3CreateBucketOperator
.
create_bucket = S3CreateBucketOperator(
task_id='s3_create_bucket',
bucket_name=BUCKET_NAME,
)
Delete an Amazon S3 Bucket¶
To delete an Amazon S3 bucket you can use
S3DeleteBucketOperator
.
delete_bucket = S3DeleteBucketOperator(
task_id='s3_delete_bucket', bucket_name=BUCKET_NAME, force_delete=True
)
Set the tags for an Amazon S3 Bucket¶
To set the tags for an Amazon S3 bucket you can use
S3PutBucketTaggingOperator
.
put_tagging = S3PutBucketTaggingOperator(
task_id='s3_put_bucket_tagging',
bucket_name=BUCKET_NAME,
key=TAG_KEY,
value=TAG_VALUE,
)
Get the tag of an Amazon S3 Bucket¶
To get the tag set associated with an Amazon S3 bucket you can use
S3GetBucketTaggingOperator
.
get_tagging = S3GetBucketTaggingOperator(
task_id='s3_get_bucket_tagging',
bucket_name=BUCKET_NAME,
)
Delete the tags of an Amazon S3 Bucket¶
To delete the tags of an Amazon S3 bucket you can use
S3DeleteBucketTaggingOperator
.
delete_tagging = S3DeleteBucketTaggingOperator(
task_id='s3_delete_bucket_tagging',
bucket_name=BUCKET_NAME,
)