airflow.providers.amazon.aws.sensors.s3

Module Contents

Classes

S3KeySensor

Waits for one or multiple keys (a file-like instance on S3) to be present in a S3 bucket.

S3KeySizeSensor

This class is deprecated.

S3KeysUnchangedSensor

Checks for changes in the number of objects at prefix in AWS S3

S3PrefixSensor

This class is deprecated.

class airflow.providers.amazon.aws.sensors.s3.S3KeySensor(*, bucket_key, bucket_name=None, wildcard_match=False, check_fn=None, aws_conn_id='aws_default', verify=None, **kwargs)[source]

Bases: airflow.sensors.base.BaseSensorOperator

Waits for one or multiple keys (a file-like instance on S3) to be present in a S3 bucket. S3 being a key/value it does not support folders. The path is just a key a resource.

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 (Union[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 (Optional[str]) – Name of the S3 bucket. Only needed when bucket_key is not provided as a full s3:// url. When specified, all the keys passed to bucket_key refers to this bucket

  • wildcard_match (bool) – whether the bucket_key should be interpreted as a Unix wildcard pattern

  • check_fn (Optional[Callable[Ellipsis, bool]]) –

    Function that receives the list of the S3 objects, 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 megabyte

    def check_fn(files: List) -> bool:
        return any(f.get('Size', 0) > 1048576 for f in files)
    

  • aws_conn_id (str) – a reference to the s3 connection

  • verify (Optional[Union[str, bool]]) –

    Whether or not to verify SSL certificates for S3 connection. By default SSL certificates are verified. You can provide the following values:

    • False: do not validate SSL certificates. SSL will still be used

      (unless use_ssl is False), but SSL certificates will not be verified.

    • path/to/cert/bundle.pem: A filename of the CA cert bundle to uses.

      You can specify this argument if you want to use a different CA cert bundle than the one used by botocore.

template_fields :Sequence[str] = ['bucket_key', 'bucket_name'][source]
poke(self, context)[source]

Function that the sensors defined while deriving this class should override.

get_hook(self)[source]

Create and return an S3Hook

class airflow.providers.amazon.aws.sensors.s3.S3KeySizeSensor(*, check_fn=None, **kwargs)[source]

Bases: S3KeySensor

This class is deprecated. Please use S3KeySensor.

static default_check_fn(data)[source]

Default function for checking that S3 Objects have size more than 0

Parameters

data (List) – List of the objects in S3 bucket.

class airflow.providers.amazon.aws.sensors.s3.S3KeysUnchangedSensor(*, bucket_name, prefix, aws_conn_id='aws_default', verify=None, inactivity_period=60 * 60, min_objects=1, previous_objects=None, allow_delete=True, **kwargs)[source]

Bases: airflow.sensors.base.BaseSensorOperator

Checks for changes in the number of objects at prefix in AWS S3 bucket and returns True if the inactivity period has passed with no increase in the number of objects. 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.

  • aws_conn_id (str) – a reference to the s3 connection

  • verify (Optional[Union[bool, str]]) –

    Whether or not to verify SSL certificates for S3 connection. By default SSL certificates are verified. You can provide the following values:

    • False: do not validate SSL certificates. SSL will still be used

      (unless use_ssl is False), but SSL certificates will not be verified.

    • path/to/cert/bundle.pem: A filename of the CA cert bundle to uses.

      You can specify this argument if you want to use a different CA cert bundle than the one used by botocore.

  • 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 (Optional[Set[str]]) – 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.

template_fields :Sequence[str] = ['bucket_name', 'prefix'][source]
hook(self)[source]

Returns S3Hook.

is_keys_unchanged(self, current_objects)[source]

Checks whether new objects have been uploaded and the inactivity_period has passed and updates the state of the sensor accordingly.

Parameters

current_objects (Set[str]) – set of object ids in bucket during last poke.

poke(self, context)[source]

Function that the sensors defined while deriving this class should override.

class airflow.providers.amazon.aws.sensors.s3.S3PrefixSensor(*, prefix, delimiter='/', **kwargs)[source]

Bases: S3KeySensor

This class is deprecated. Please use S3KeySensor.

template_fields :Sequence[str] = ['prefix', 'bucket_name'][source]

Was this entry helpful?