airflow.providers.amazon.aws.sensors.s3¶
Classes¶
Waits for one or multiple keys (a file-like instance on S3) to be present in a S3 bucket. |
|
Return True if inactivity_period has passed with no increase in the number of objects matching prefix. |
Module Contents¶
- class airflow.providers.amazon.aws.sensors.s3.S3KeySensor(*, bucket_key, bucket_name=None, wildcard_match=False, check_fn=None, verify=None, deferrable=conf.getboolean('operators', 'default_deferrable', fallback=False), use_regex=False, metadata_keys=None, **kwargs)[source]¶
Bases:
airflow.providers.amazon.aws.sensors.base_aws.AwsBaseSensor
[airflow.providers.amazon.aws.hooks.s3.S3Hook
]Waits for one or multiple keys (a file-like instance on S3) to be present in a S3 bucket.
The path is just a key/value pointer to a resource for the given S3 path. Note: S3 does not support folders directly, and only provides key/value pairs.
See also
For more information on how to use this sensor, take a look at the guide: Wait on an Amazon S3 key
- Parameters:
bucket_key (str | list[str]) – The key(s) being waited on. Supports full s3:// style url or relative path from root level. When it’s specified as a full s3:// url, please leave bucket_name as None
bucket_name (str | None) – Name of the S3 bucket. Only needed when
bucket_key
is not provided as a fulls3://
url. When specified, all the keys passed tobucket_key
refers to this bucketwildcard_match (bool) – whether the bucket_key should be interpreted as a Unix wildcard pattern
check_fn (Callable[Ellipsis, bool] | None) –
Function that receives the list of the S3 objects with the context values, and returns a boolean: -
True
: the criteria is met -False
: the criteria isn’t met Example: Wait for any S3 object size more than 1 megabytedef check_fn(files: List, **kwargs) -> bool: return any(f.get('Size', 0) > 1048576 for f in files)
deferrable (bool) – Run operator in the deferrable mode
use_regex (bool) – whether to use regex to check bucket
metadata_keys (list[str] | None) – List of head_object attributes to gather and send to
check_fn
. Acceptable values: Any top level attribute returned by s3.head_object. Specify * to return all available attributes. Default value: “Size”. If the requested attribute is not found, the key is still included and the value is None.aws_conn_id – The Airflow connection used for AWS credentials. If this is
None
or empty then the default boto3 behaviour is used. If running Airflow in a distributed manner and aws_conn_id is None or empty, then default boto3 configuration would be used (and must be maintained on each worker node).region_name – AWS region_name. If not specified then the default boto3 behaviour is used.
verify (str | bool | None) – Whether or not to verify SSL certificates. See: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html
- template_fields: collections.abc.Sequence[str][source]¶
- class airflow.providers.amazon.aws.sensors.s3.S3KeysUnchangedSensor(*, bucket_name, prefix, verify=None, inactivity_period=60 * 60, min_objects=1, previous_objects=None, allow_delete=True, deferrable=conf.getboolean('operators', 'default_deferrable', fallback=False), **kwargs)[source]¶
Bases:
airflow.providers.amazon.aws.sensors.base_aws.AwsBaseSensor
[airflow.providers.amazon.aws.hooks.s3.S3Hook
]Return True if inactivity_period has passed with no increase in the number of objects matching prefix.
Note, this sensor will not behave correctly in reschedule mode, as the state of the listed objects in the S3 bucket will be lost between rescheduled invocations.
See also
For more information on how to use this sensor, take a look at the guide: Wait on Amazon S3 prefix changes
- Parameters:
bucket_name (str) – Name of the S3 bucket
prefix (str) – The prefix being waited on. Relative path from bucket root level. https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html
inactivity_period (float) – The total seconds of inactivity to designate keys unchanged. Note, this mechanism is not real time and this operator may not return until a poke_interval after this period has passed with no additional objects sensed.
min_objects (int) – The minimum number of objects needed for keys unchanged sensor to be considered valid.
previous_objects (set[str] | None) – The set of object ids found during the last poke.
allow_delete (bool) – Should this sensor consider objects being deleted between pokes valid behavior. If true a warning message will be logged when this happens. If false an error will be raised.
deferrable (bool) – Run sensor in the deferrable mode
aws_conn_id – The Airflow connection used for AWS credentials. If this is
None
or empty then the default boto3 behaviour is used. If running Airflow in a distributed manner and aws_conn_id is None or empty, then default boto3 configuration would be used (and must be maintained on each worker node).region_name – AWS region_name. If not specified then the default boto3 behaviour is used.
verify (bool | str | None) – Whether or not to verify SSL certificates. See: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html
- template_fields: collections.abc.Sequence[str][source]¶
- last_activity_time: datetime.datetime | None = None[source]¶
- is_keys_unchanged(current_objects)[source]¶
Check for new objects after the inactivity_period and update the sensor state accordingly.