airflow.providers.amazon.aws.operators.s3
¶
This module contains AWS S3 operators.
Module Contents¶
Classes¶
This operator creates an S3 bucket |
|
This operator deletes an S3 bucket |
|
This operator gets tagging from an S3 bucket |
|
This operator puts tagging for an S3 bucket. |
|
This operator deletes tagging from an S3 bucket. |
|
Creates a copy of an object that is already stored in S3. |
|
Creates a new object from data as string or bytes. |
|
To enable users to delete single object or multiple objects from |
|
Copies data from a source S3 location to a temporary location on the |
|
List all objects from the bucket with the given string prefix in name. |
|
List all subfolders from the bucket with the given string prefix in name. |
Attributes¶
- airflow.providers.amazon.aws.operators.s3.BUCKET_DOES_NOT_EXIST_MSG = Bucket with name: %s doesn't exist[source]¶
- class airflow.providers.amazon.aws.operators.s3.S3CreateBucketOperator(*, bucket_name, aws_conn_id='aws_default', region_name=None, **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
This operator creates an S3 bucket
See also
For more information on how to use this operator, take a look at the guide: Create an Amazon S3 bucket
- Parameters
bucket_name (str) – This is bucket name you want to create
aws_conn_id (Optional[str]) – 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 (Optional[str]) – AWS region_name. If not specified fetched from connection.
- class airflow.providers.amazon.aws.operators.s3.S3DeleteBucketOperator(bucket_name, force_delete=False, aws_conn_id='aws_default', **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
This operator deletes an S3 bucket
See also
For more information on how to use this operator, take a look at the guide: Delete an Amazon S3 bucket
- Parameters
bucket_name (str) – This is bucket name you want to delete
force_delete (bool) – Forcibly delete all objects in the bucket before deleting the bucket
aws_conn_id (Optional[str]) – 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).
- class airflow.providers.amazon.aws.operators.s3.S3GetBucketTaggingOperator(bucket_name, aws_conn_id='aws_default', **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
This operator gets tagging from an S3 bucket
See also
For more information on how to use this operator, take a look at the guide: Get the tag of an Amazon S3 bucket
- Parameters
bucket_name (str) – This is bucket name you want to reference
aws_conn_id (Optional[str]) – 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).
- class airflow.providers.amazon.aws.operators.s3.S3PutBucketTaggingOperator(bucket_name, key=None, value=None, tag_set=None, aws_conn_id='aws_default', **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
This operator puts tagging for an S3 bucket.
See also
For more information on how to use this operator, take a look at the guide: Set the tags for an Amazon S3 bucket
- Parameters
bucket_name (str) – The name of the bucket to add tags to.
key (Optional[str]) – The key portion of the key/value pair for a tag to be added. If a key is provided, a value must be provided as well.
value (Optional[str]) – The value portion of the key/value pair for a tag to be added. If a value is provided, a key must be provided as well.
tag_set (Optional[List[Dict[str, str]]]) – A List of key/value pairs.
aws_conn_id (Optional[str]) – 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 the default boto3 configuration would be used (and must be maintained on each worker node).
- class airflow.providers.amazon.aws.operators.s3.S3DeleteBucketTaggingOperator(bucket_name, aws_conn_id='aws_default', **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
This operator deletes tagging from an S3 bucket.
See also
For more information on how to use this operator, take a look at the guide: Delete the tags of an Amazon S3 bucket
- Parameters
bucket_name (str) – This is the name of the bucket to delete tags from.
aws_conn_id (Optional[str]) – 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).
- class airflow.providers.amazon.aws.operators.s3.S3CopyObjectOperator(*, source_bucket_key, dest_bucket_key, source_bucket_name=None, dest_bucket_name=None, source_version_id=None, aws_conn_id='aws_default', verify=None, acl_policy=None, **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
Creates a copy of an object that is already stored in S3.
Note: the S3 connection used here needs to have access to both source and destination bucket/key.
See also
For more information on how to use this operator, take a look at the guide: Copy an Amazon S3 object
- Parameters
source_bucket_key (str) –
The key of the source object. (templated)
It can be either full s3:// style url or relative path from root level.
When it’s specified as a full s3:// url, please omit source_bucket_name.
dest_bucket_key (str) –
The key of the object to copy to. (templated)
The convention to specify dest_bucket_key is the same as source_bucket_key.
source_bucket_name (Optional[str]) –
Name of the S3 bucket where the source object is in. (templated)
It should be omitted when source_bucket_key is provided as a full s3:// url.
dest_bucket_name (Optional[str]) –
Name of the S3 bucket to where the object is copied. (templated)
It should be omitted when dest_bucket_key is provided as a full s3:// url.
source_version_id (Optional[str]) – Version ID of the source object (OPTIONAL)
aws_conn_id (str) – Connection id of the S3 connection to use
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,
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.
acl_policy (Optional[str]) – String specifying the canned ACL policy for the file being uploaded to the S3 bucket.
- class airflow.providers.amazon.aws.operators.s3.S3CreateObjectOperator(*, s3_bucket=None, s3_key, data, replace=False, encrypt=False, acl_policy=None, encoding=None, compression=None, aws_conn_id='aws_default', verify=None, **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
Creates a new object from data as string or bytes.
See also
For more information on how to use this operator, take a look at the guide: Create an Amazon S3 object
- Parameters
s3_bucket (Optional[str]) – Name of the S3 bucket where to save the object. (templated) It should be omitted when bucket_key is provided as a full s3:// url.
s3_key (str) – The key of the object to be created. (templated) It can be either full s3:// style url or relative path from root level. When it’s specified as a full s3:// url, please omit bucket_name.
data (Union[str, bytes]) – string or bytes to save as content.
replace (bool) – If True, it will overwrite the key if it already exists
encrypt (bool) – If True, the file will be encrypted on the server-side by S3 and will be stored in an encrypted form while at rest in S3.
acl_policy (Optional[str]) – String specifying the canned ACL policy for the file being uploaded to the S3 bucket.
encoding (Optional[str]) – The string to byte encoding. It should be specified only when data is provided as string.
compression (Optional[str]) – Type of compression to use, currently only gzip is supported. It can be specified only when data is provided as string.
aws_conn_id (str) – Connection id of the S3 connection to use
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,
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.
- class airflow.providers.amazon.aws.operators.s3.S3DeleteObjectsOperator(*, bucket, keys=None, prefix=None, aws_conn_id='aws_default', verify=None, **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
To enable users to delete single object or multiple objects from a bucket using a single HTTP request.
See also
For more information on how to use this operator, take a look at the guide: Delete Amazon S3 objects
- Parameters
bucket (str) – Name of the bucket in which you are going to delete object(s). (templated)
keys (Optional[Union[str, list]]) –
The key(s) to delete from S3 bucket. (templated)
When
keys
is a string, it’s supposed to be the key name of the single object to delete.When
keys
is a list, it’s supposed to be the list of the keys to delete.prefix (Optional[str]) – Prefix of objects to delete. (templated) All objects matching this prefix in the bucket will be deleted.
aws_conn_id (str) – Connection id of the S3 connection to use
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,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.
- class airflow.providers.amazon.aws.operators.s3.S3FileTransformOperator(*, source_s3_key, dest_s3_key, transform_script=None, select_expression=None, script_args=None, source_aws_conn_id='aws_default', source_verify=None, dest_aws_conn_id='aws_default', dest_verify=None, replace=False, **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
Copies data from a source S3 location to a temporary location on the local filesystem. Runs a transformation on this file as specified by the transformation script and uploads the output to a destination S3 location.
The locations of the source and the destination files in the local filesystem is provided as a first and second arguments to the transformation script. The transformation script is expected to read the data from source, transform it and write the output to the local destination file. The operator then takes over control and uploads the local destination file to S3.
S3 Select is also available to filter the source contents. Users can omit the transformation script if S3 Select expression is specified.
See also
For more information on how to use this operator, take a look at the guide: Transform an Amazon S3 object
- Parameters
source_s3_key (str) – The key to be retrieved from S3. (templated)
dest_s3_key (str) – The key to be written from S3. (templated)
transform_script (Optional[str]) – location of the executable transformation script
select_expression – S3 Select expression
script_args (Optional[Sequence[str]]) – arguments for transformation script (templated)
source_aws_conn_id (str) – source s3 connection
source_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.
This is also applicable to
dest_verify
.dest_aws_conn_id (str) – destination s3 connection
dest_verify (Optional[Union[bool, str]]) – Whether or not to verify SSL certificates for S3 connection. See:
source_verify
replace (bool) – Replace dest S3 key if it already exists
- class airflow.providers.amazon.aws.operators.s3.S3ListOperator(*, bucket, prefix='', delimiter='', aws_conn_id='aws_default', verify=None, **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
List all objects from the bucket with the given string prefix in name.
This operator returns a python list with the name of objects which can be used by xcom in the downstream task.
See also
For more information on how to use this operator, take a look at the guide: List Amazon S3 objects
- Parameters
bucket (str) – The S3 bucket where to find the objects. (templated)
prefix (str) – Prefix string to filters the objects whose name begin with such prefix. (templated)
delimiter (str) – the delimiter marks key hierarchy. (templated)
aws_conn_id (str) – The connection ID to use when connecting to S3 storage.
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.
- Example:
The following operator would list all the files (excluding subfolders) from the S3
customers/2018/04/
key in thedata
bucket.s3_file = S3ListOperator( task_id='list_3s_files', bucket='data', prefix='customers/2018/04/', delimiter='/', aws_conn_id='aws_customers_conn' )
- class airflow.providers.amazon.aws.operators.s3.S3ListPrefixesOperator(*, bucket, prefix, delimiter, aws_conn_id='aws_default', verify=None, **kwargs)[source]¶
Bases:
airflow.models.BaseOperator
List all subfolders from the bucket with the given string prefix in name.
This operator returns a python list with the name of all subfolders which can be used by xcom in the downstream task.
See also
For more information on how to use this operator, take a look at the guide: List Amazon S3 prefixes
- Parameters
bucket (str) – The S3 bucket where to find the subfolders. (templated)
prefix (str) – Prefix string to filter the subfolders whose name begin with such prefix. (templated)
delimiter (str) – the delimiter marks subfolder hierarchy. (templated)
aws_conn_id (str) – The connection ID to use when connecting to S3 storage.
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.
- Example:
The following operator would list all the subfolders from the S3
customers/2018/04/
prefix in thedata
bucket.s3_file = S3ListPrefixesOperator( task_id='list_s3_prefixes', bucket='data', prefix='customers/2018/04/', delimiter='/', aws_conn_id='aws_customers_conn' )