Skip to main content

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


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. 

Comments

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(...

How to audit an Azure Cosmos DB

In this post, we will talk about how we can audit an Azure Cosmos DB database. Before jumping into the problem let us define the business requirement: As an Administrator I want to be able to audit all changes that were done to specific collection inside my Azure Cosmos DB. The requirement is simple, but can be a little tricky to implement fully. First of all when you are using Azure Cosmos DB or any other storage solution there are 99% odds that you’ll have more than one system that writes data to it. This means that you have or not have control on the systems that are doing any create/update/delete operations. Solution 1: Diagnostic Logs Cosmos DB allows us activate diagnostics logs and stream the output a storage account for achieving to other systems like Event Hub or Log Analytics. This would allow us to have information related to who, when, what, response code and how the access operation to our Cosmos DB was done. Beside this there is a field that specifies what was th...

Cloud Myths: Cloud is Cheaper (Pill 1 of 5 / Cloud Pills)

Cloud Myths: Cloud is Cheaper (Pill 1 of 5 / Cloud Pills) The idea that moving to the cloud reduces the costs is a common misconception. The cloud infrastructure provides flexibility, scalability, and better CAPEX, but it does not guarantee lower costs without proper optimisation and management of the cloud services and infrastructure. Idle and unused resources, overprovisioning, oversize databases, and unnecessary data transfer can increase running costs. The regional pricing mode, multi-cloud complexity, and cost variety add extra complexity to the cost function. Cloud adoption without a cost governance strategy can result in unexpected expenses. Improper usage, combined with a pay-as-you-go model, can result in a nightmare for business stakeholders who cannot track and manage the monthly costs. Cloud-native services such as AI services, managed databases, and analytics platforms are powerful, provide out-of-the-shelve capabilities, and increase business agility and innovation. H...