Implementing an ETL process in AWS and Azure that fetch data from FTP

Source: http://vunvulearadu.blogspot.com/2020/02/implementing-etl-process-in-aws-and.html

Have you ever had to automate the data ingestion from an FTP (SFTP) to cloud? The challenge is not to read data from an (S)FTP. The challenge is to do this reliably with minimal investment.

In an ideal world, you would go with an approach where you would use an ETL or orchestration solution provided by the cloud. The reality is that you don’t have cloud services that are fully integrated with (S)FTP. On top of this, you need to fight with the network connectivity that might not be so reliable as you think.

Let’s see how we can design a solution that:

  • 1. Access (S)FTP content that it is on-premises
  • 2. Process and transform the data
  • 3. Push the content to a MySQL database and updates a cache.

The requirements are specific to an ETL process, where we need to extract data from a repository, transform the data and store it inside the database.

Running the solution on Microsoft Azure

The first Microsoft Azure service that we should take into account is the Azure Data Factory. It is an ETL service, fully managed by Azure. If we take a look on the connectors list, we notify that FTP connector is supported out of the box. It means that the copy procedure can be done without having to do custom steps.

When we implement the pipeline inside Azure Data Factory we should ensure that one of the first activities is the copy activity from (S)FTP to Azure Blob Storage. For a typical case, you shall copy the content (file) to the Blob Storage and only after that to start to process it.

The Azure Data Factory Pipeline could look similar to the one below:

  • 1. Move data from (S)FTP to Azure Blob Storage
  • 2. Transform each copied file using an Azure Function
  • 3. Push the output to Azure MySQL
  • 4. Invalidate Azure Cache for Redis keys where information was updated

The solution is easy to implement, with minimal lines of code. The (S)FTP connector is crucial to delegate the copy responsibility.

Running the solution on AWS

The equivalent solution implement inside AWS environment should be around AWS Glue — the full managed ETL service available inside AWS. The tricky part with AWS Glue is the lack of support for an (S)FTP inside AWS Glue.

Custom Spark Job

One option is to define a job that copies content from (S)FTP to the AWS S3. The tricky part with this is that there is no out-of-the-shelve job that can connect to an (S)FTP. Meaning that you need to run your own script/package that can connect to (S)FTP and copy content to AWS S3.

To do this we define a new Spark job where we can run our own script. The script can run with success an FPT library like “cdata.jdbc.ftp” that would be called by our Python script. If you want you can use your own library that connects to the (S)FTP and run it.

If you want to use an AWS Function inside the Job, you should be aware that at this moment in time there is no support to invoke a function directly. So, you will need to use the Spark Job and call your function or see the second option

AWS Lambda and AWS Glue

The second option is based on an AWS Lambda Function that is triggered at a specific time interval. The function connects to the (S)FTP account and copies the content to an AWS S3 bucket. Once we have content inside the bucket we can trigger an AWS Glue crawler to create the catalogue and table definition if needed.

From that moment on, we can define an AWS Glue job that does the transformation and copies the content to AWS RDS for MySQL and AWS ElasticCache. The trigger can be the AWS Lambda function itself of we could monitor the AWS S3 and use the AWS CloudWatch events for new file.

As we can see both providers are offering similar solutions. The only difference between the two of them is the (S)FTP connector provided by Azure Data Factory that enables us to copy content from (S)FTP without having to do any custom steps.