Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sample dag and doc for S3ListOperator #23449

Merged
merged 2 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions airflow/providers/amazon/aws/example_dags/example_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
S3DeleteObjectsOperator,
S3FileTransformOperator,
S3GetBucketTaggingOperator,
S3ListOperator,
S3PutBucketTaggingOperator,
)
from airflow.providers.amazon.aws.sensors.s3 import S3KeySensor, S3KeysUnchangedSensor
Expand Down Expand Up @@ -115,6 +116,14 @@ def check_fn(files: List) -> bool:
)
# [END howto_operator_s3_create_object]

# [START howto_operator_s3_list]
list_keys = S3ListOperator(
task_id="s3_list_operator",
bucket=BUCKET_NAME,
prefix=PREFIX,
)
# [END howto_operator_s3_list]

# [START howto_sensor_s3_key_single_key]
# Check if a file exists
s3_sensor_one_key = S3KeySensor(
Expand Down Expand Up @@ -193,6 +202,7 @@ def check_fn(files: List) -> bool:
get_tagging,
delete_tagging,
s3_create_object,
list_keys,
[s3_sensor_one_key, s3_sensor_two_keys, s3_sensor_key_function],
s3_copy_object,
s3_sensor_keys_unchanged,
Expand Down
4 changes: 4 additions & 0 deletions airflow/providers/amazon/aws/operators/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ class S3ListOperator(BaseOperator):
This operator returns a python list with the name of objects which can be
used by `xcom` in the downstream task.

.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:S3ListOperator`

:param bucket: The S3 bucket where to find the objects. (templated)
:param prefix: Prefix string to filters the objects whose name begin with
such prefix. (templated)
Expand Down
15 changes: 15 additions & 0 deletions docs/apache-airflow-providers-amazon/operators/s3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ To create a new (or replace) Amazon S3 object you can use
:start-after: [START howto_operator_s3_create_object]
:end-before: [END howto_operator_s3_create_object]

.. _howto/operator:S3ListOperator:

List Amazon S3 objects
----------------------

To list all Amazon S3 objects within an Amazon S3 bucket you can use
:class:`~airflow.providers.amazon.aws.operators.s3.S3ListOperator`.
You can specify a ``prefix`` to filter the objects whose name begins with such prefix.

.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/example_s3.py
:language: python
:dedent: 4
:start-after: [START howto_operator_s3_list]
:end-before: [END howto_operator_s3_list]

.. _howto/operator:S3CopyObjectOperator:

Copy an Amazon S3 object
Expand Down