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

Why Database Modernization Matters for AI

  When companies transition to the cloud, they typically begin with applications and virtual machines, which is often the easier part of the process. The actual complexity arises later when databases are moved. To save time and effort, cloud adoption is more of a cloud migration in an IaaS manner, fulfilling current, but not future needs. Even organisations that are already in the cloud find that their databases, although “migrated,” are not genuinely modernised. This disparity becomes particularly evident when they begin to explore AI technologies. Understanding Modernisation Beyond Migration Database modernisation is distinct from merely relocating an outdated database to Azure. It's about making your data layer ready for future needs, like automation, real-time analytics, and AI capabilities. AI needs high throughput, which can be achieved using native DB cloud capabilities. When your database runs in a traditional setup (even hosted in the cloud), in that case, you will enc...

Cloud Myths: Migrating to the cloud is quick and easy (Pill 2 of 5 / Cloud Pills)

The idea that migration to the cloud is simple, straightforward and rapid is a wrong assumption. It’s a common misconception of business stakeholders that generates delays, budget overruns and technical dept. A migration requires laborious planning, technical expertise and a rigorous process.  Migrations, especially cloud migrations, are not one-size-fits-all journeys. One of the most critical steps is under evaluation, under budget and under consideration. The evaluation phase, where existing infrastructure, applications, database, network and the end-to-end estate are evaluated and mapped to a cloud strategy, is crucial to ensure the success of cloud migration. Additional factors such as security, compliance, and system dependencies increase the complexity of cloud migration.  A misconception regarding lift-and-shits is that they are fast and cheap. Moving applications to the cloud without changes does not provide the capability to optimise costs and performance, leading to ...

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