How to create a Lambda function for data ingestion on the Data Analytics Platform
Check the feasibility of a Lambda function approach
Before starting, it is advisable to discuss with the DAP team that a Lambda function is the most appropriate approach to take for your data ingestion task.
Here are some factors to consider before proceeding:
-
Execution Time
Lambda functions have execution time limits (currently 15 minutes per invocation). Ensure that your workload can execute within this time limit. If not, have a discussion with the DAP team to identify a more suitable approach.
-
Supported Runtimes and dependencies
Lambda supports multiple programming languages including Python. Certain Python packages may need to be imported. This can be achieved through Lambda layers.
-
Monitoring
Lambda integrates with AWS CloudWatch for logging and monitoring; ensure that the permissions set includes the ability to write logs for debugging later on.
Outline what you need your Lambda function to do
On the Data Analytics Platform, we typically use AWS Lambda to perform simple ingestion and data processing tasks which do not require the resource-intensive infrastructure of an AWS Glue job, for example:
- Making an API call and writing the response to the landing zone, including a crawler execution
- Reading in data from a Google Sheet
- Moving data from one zone to another zone, with a simple refinement
- Event-driven processing, for example once new data arrives in S3, a Lambda is triggered to perform a task immediately
- Near Real-time processing for example, when a new person is added to a permissions group, a Lambda is triggered to grant this permission
If your process involves reading in very large datasets, applying complex algorithms using Spark or and undertaking data transformations with multiple datasets, then this might be better suited to a different approach such as AWS Glue.
Requesting the correct permissions set
You will need to provide the DAP team with the following information so that the correct roles and policies can be set up for your Lambda. At the time of writing it is advisable to set up a short meeting with the DAP team to discuss your requirements :
- The department or service area that the process is for e.g. Housing
- Where data will be ingested / read from e.g. an external API; housing-zone-raw database
- Where data needs to be written to e.g. landing zone, refined zone
- The kind of actions that needed e.g. writing data to S3 s3:PutObject
- Whether logging is to be enabled
- Whether secrets needs to be accessed from AWS Secret Manager (and what the secrets are called)
- Any other services needed for your Lambda task e.g. AWS Glue Crawler StartCrawler action