@@ -204,8 +204,8 @@ Wait on an Amazon S3 key
204204To wait for one or multiple keys to be present in an Amazon S3 bucket you can use
205205:class: `~airflow.providers.amazon.aws.sensors.s3.S3KeySensor `.
206206For each key, it calls
207- `head_object <https://boto3.amazonaws. com/v1/documentation/api/ latest/reference/services/s3.html#S3.Client.head_object >`__
208- API (or `list_objects_v2 <https://boto3.amazonaws. com/v1/documentation/api/ latest/reference/services/s3.html#S3.Client.list_objects_v2 >`__
207+ `head_object <https://docs.aws.amazon. com/boto3/ latest/reference/services/s3/client/head_object .html >`__
208+ API (or `list_objects_v2 <https://docs.aws.amazon. com/boto3/ latest/reference/services/s3/client/list_objects_v2 .html >`__
209209API if ``wildcard_match `` is ``True ``) to check whether it is present or not.
210210Please keep in mind, especially when used to check a large volume of keys, that it makes one API call per key.
211211
@@ -217,6 +217,7 @@ To check one file:
217217 :start-after: [START howto_sensor_s3_key_single_key]
218218 :end-before: [END howto_sensor_s3_key_single_key]
219219
220+
220221To check multiple files:
221222
222223.. exampleinclude :: /../../amazon/tests/system/amazon/aws/example_s3.py
@@ -225,6 +226,7 @@ To check multiple files:
225226 :start-after: [START howto_sensor_s3_key_multiple_keys]
226227 :end-before: [END howto_sensor_s3_key_multiple_keys]
227228
229+
228230To check a file with regular expression:
229231
230232.. exampleinclude :: /../../amazon/tests/system/amazon/aws/example_s3.py
@@ -233,6 +235,7 @@ To check a file with regular expression:
233235 :start-after: [START howto_sensor_s3_key_regex]
234236 :end-before: [END howto_sensor_s3_key_regex]
235237
238+
236239To check with an additional custom check you can define a function which receives a list of matched S3 object
237240attributes and returns a boolean:
238241
@@ -241,11 +244,13 @@ attributes and returns a boolean:
241244
242245This function is called for each key passed as parameter in ``bucket_key ``.
243246The reason why the parameter of this function is a list of objects is when ``wildcard_match `` is ``True ``,
244- multiple files can match one key. The list of matched S3 object attributes contain only the size and is this format:
247+ multiple files can match one key. The list of matched S3 object attributes contains the associated S3 key as well as
248+ any valid keys in the ``head_object `` response. If no ``metadata_keys `` are given, it defaults to the size
249+ and is in this format:
245250
246251.. code-block :: python
247252
248- [{" Size" : int }]
253+ [{" Key " : str , " Size" : int }]
249254
250255 .. exampleinclude :: /../../amazon/tests/system/amazon/aws/example_s3.py
251256 :language: python
@@ -259,6 +264,14 @@ multiple files can match one key. The list of matched S3 object attributes conta
259264 :start-after: [START howto_sensor_s3_key_function]
260265 :end-before: [END howto_sensor_s3_key_function]
261266
267+ To filter by S3 key:
268+
269+ .. exampleinclude :: /../../amazon/tests/system/amazon/aws/example_s3.py
270+ :language: python
271+ :dedent: 4
272+ :start-after: [START howto_sensor_s3_key_function_filter_definition]
273+ :end-before: [END howto_sensor_s3_key_function_filter_definition]
274+
262275You can also run this operator in deferrable mode by setting the parameter ``deferrable `` to True.
263276This will lead to efficient utilization of Airflow workers as polling for job status happens on
264277the triggerer asynchronously. Note that this will need triggerer to be available on your Airflow deployment.
0 commit comments