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(...

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine: threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration: TeamCity .NET 4.51 EF 6.0.2 VS2013 It see...

Navigating Cloud Strategy after Azure Central US Region Outage

 Looking back, July 19, 2024, was challenging for customers using Microsoft Azure or Windows machines. Two major outages affected customers using CrowdStrike Falcon or Microsoft Azure computation resources in the Central US. These two outages affected many people and put many businesses on pause for a few hours or even days. The overlap of these two issues was a nightmare for travellers. In addition to blue screens in the airport terminals, they could not get additional information from the airport website, airline personnel, or the support line because they were affected by the outage in the Central US region or the CrowdStrike outage.   But what happened in reality? A faulty CrowdStrike update affected Windows computers globally, from airports and healthcare to small businesses, affecting over 8.5m computers. Even if the Falson Sensor software defect was identified and a fix deployed shortly after, the recovery took longer. In parallel with CrowdStrike, Microsoft provi...