How to Copy/Move S3 Files With Apache Airflow
With Apache-Airflow's AWS providers S3 operations are a cake-walk.
Create an AWS account, and ensure you have the right roles and policies set before proceeding with the following code
Create a working instance of Apache Airflow in local or on your preferred cloud provider
Create an Airflow connection with
AWS_SECRET, AWS_ACCESS and role_arn
The connection extras will look something like this. Replace
<your-role-arn>
with the AWS role that you created.\{"region_name": "us-west-2", "role_arn": "<your-role-arn>", "assume_role_method": "assume_role"}
Add the following DAG to your dags folder
Run the code
You can change the
transform_script
form/bin/cp
to/bin/mv
to move files.Note that the
dest_key
has{{ds}}
in it. This ensures a new blob is created every time the DAG runs.You can also pass a python script as a string to
transform_script
Last updated