AWS Serverless FTP File Processing Service

· 4 min

A common business task is file processing: fetch a file from somewhere like an FTP server, read and transform it, and store the results in a database. There are dozens of ways to do it, from batch scripts to Windows services. This post takes a modern approach using AWS.

The scenario

Acme Corporation needs a file processing system:

Polling and transfer

Here's the design, and what each part is for.

1. Lambda (file fetch)

This is the poller. It connects to the FTP server on a schedule, checks a directory for files, downloads them and puts them in an S3 bucket. Nothing else:

2. CloudWatch

Because this Lambda only polls and downloads, its CloudWatch logs only contain those I/O events, which makes them easier to follow. Alarms can alert people to problems through SNS or email, depending on requirements. Beyond that, it's simply very useful for tracking events and debugging.

3. S3 (file bucket)

The bucket is a temporary store for downloaded files, and a key part of making the service distributed and resilient. Files reach it through a VPC endpoint, so they never cross the public internet. Two S3 features do a lot of the work:

Parsing and processing

4. SQS

The queue decouples the two halves of the service and adds flexibility and resilience:

5. Lambda (file processing)

This Lambda reads each file, transforms the data, calls a third-party service to validate some attributes and stores the result in a DynamoDB table for other services to use.

6. SNS

SNS sends a notification after each file is processed. That could be an email, or a log of success. Once there's a consistent baseline, an alarm can trigger a manual review when the count drops below it.

Worth a mention

I've left out configuration this scenario doesn't need, to keep the post short. A few options are worth considering for similar systems:

The result covers what's expected of a standard file processing system: one bad file doesn't stop the rest, and the culprit is flagged for inspection. Much of the finer detail is skipped to keep it short.