AWS Lambda Function to connect to FTP, download files and save them to S3 bucket
#AWS Lambda FTP Function
The following How-To will demonstrate how to use AWS Lambda service to:
archive
folder)Later this will trigger another event on Lambda to parse these files and send data to API Gateway. Make sure that S3 and Lambda are on the same region, otherwise Lambda event will not work.
Flow diagram:
This how-to assume that you have an AWS account with admin access.
Create S3 bucket.
Create Role to access this S3 bucket
lambda_ftp_to_s3
AWSLambdaFullAccess
and click Next.Create Lambda function
Click on Get started now.
Skip the next screen as it just showing pre-defined functions
In configure function, please fill the form as below
In the code section, copy and paste the code in aws_lambda_ftp_function.py
**Please make sure to populate data with your own specific credentials for S3 bucket name and FTP connection.
Handler, keep it as it is
Role, use the one that we have created on step 2.
Timeout is quite improtant in this application as you may expect delays, slow FTP connection or large number of files to download. I would put it as 1 minute.
Click create function
Now we need to setup the event to call this function to fetch FTP and download files.
Event sources
CloudWatch Events - Schedule
Schedule expression
To test your function, run Test from function page and you should be able to see output at buttom.
If everything was ok, you should be able to see files in your S3.