
AWS Lambda Application Performance and Integration
DynamoDB Non-relational Database Structure
The DynamoDB database is a non-relational, schema-less database that uses partition and sort keys to optimize queries. In this implementation, fields such as Field02 and Field04 are used as the partition and sort keys, respectively, to create an efficient index for data retrieval. This allows structured querying while maintaining flexibility in the schema.
Lambda Function Using Node.js
The AWS Lambda function is written in Node.js and is designed to asynchronously handle API calls. It receives parameters from the frontend, parses them from the request body, and performs queries using a GSI (Global Secondary Index) on the DynamoDB table. The function uses structured key conditions and error handling to manage missing or malformed data inputs.
IAM Permissions for Secure Access
IAM (Identity and Access Management) permissions are configured to restrict and authorize access to the DynamoDB service. This ensures that only the Lambda function with proper permissions can read from or write to the database, enhancing the security posture of the system.
Exposing Lambda as an API with Function URL
The Lambda function is made accessible as a RESTful API using the 'Function URL' feature in AWS. This enables external systems, such as frontend applications, to make HTTP requests directly to the function, simplifying API integration.
Frontend PHP Integration with Lambda API
The frontend PHP application sends HTTP POST requests to the Lambda function using cURL. It captures user input (channel, start date, end date), encodes it into JSON, and transmits it via the configured Lambda URL. This enables dynamic querying of the DynamoDB database through a web interface.
Monitoring with AWS CloudWatch
AWS CloudWatch is used to monitor performance and detect potential security issues across the application stack, including the database, Lambda functions, and frontend access patterns. Logs provide visibility into execution times, errors, and anomalies for ongoing optimization and security auditing.
Lambda Query Execution Flow Explained
The Lambda function structure includes parsing the incoming event, validating parameters, building the query command with a KeyConditionExpression, and awaiting a response from DynamoDB. Responses are returned in JSON format to the frontend. Errors are captured using try-catch blocks, and appropriate HTTP status codes are returned.
PHP Form and cURL Call to Lambda
The PHP form captures user inputs and uses cURL to send them to the Lambda API. It includes methods to handle HTTP headers, return codes, and display responses, offering a seamless connection between frontend and backend services for database querying.
Lambda Function:
Language: Node JS
Queries the Dynamo Database with Index using partition and sort key. Look for a third value using Table SCAN.
Front END. PHP
$ch = curl_init($fullUrl);
$response = curl_exec($ch);
Call the Lambda Function API with parameters to get DATABASE results.
Dynamo non-relational plain database
Create the Dynamo table using Dynamo console.
The two thousand records to insert are on the JSON file marketingdata_dynamo.json included in this lesson.
Run the Python script in this file, batch_upload_dynamo.py, as explained in the video.
Verify the records by reading the contents of the table in the DYNAMO console.
The Global Secondary Index helps to do a query using parameters coming from the PHP frontend.
Lambda Function:
Language: Node JS
Queries the Dynamo Database with an Index using partition and sort key. Look for a third value using Table SCAN.
The Lambda function file is attached here as index.mjs
The Lambda function needs permission to access the Dynamo. In this lecture, we will learn how to do that with the IAM role of AWS.
In this lesson we create the URL of the Lambda function and show how to call it from the PHP frontend. The PHP file is attached in this lecture as CallLambdaqueryMarketing.php
Check if there is a positive correspondence between the Lambda calls and Dynamo table execution. It has no logical relationship; it could indicate a security breach because the DYNAMO table may contain a ghost caller.
DynamoDB Non-relational Database Structure
The DynamoDB database is a non-relational, schema-less database that uses partition and sort keys to optimize queries. In this implementation, fields such as Field02 and Field04 are used as the partition and sort keys, respectively, to create an efficient index for data retrieval. This allows structured querying while maintaining flexibility in the schema.
Lambda Function Using Node.js
The AWS Lambda function is written in Node.js and is designed to asynchronously handle API calls. It receives parameters from the frontend, parses them from the request body, and performs queries using a GSI (Global Secondary Index) on the DynamoDB table. The function uses structured key conditions and error handling to manage missing or malformed data inputs.
Exposing Lambda as an API with Function URL
The Lambda function is made accessible as a RESTful API using the 'Function URL' feature in AWS. This enables external systems, such as frontend applications, to make HTTP requests directly to the function, simplifying API integration.
Frontend PHP Integration with Lambda API
The frontend PHP application sends HTTP POST requests to the Lambda function using cURL. It captures user input (channel, start date, end date), encodes it into JSON, and transmits it via the configured Lambda URL. This enables dynamic querying of the DynamoDB database through a web interface.
Monitoring with AWS CloudWatch
AWS CloudWatch is used to monitor performance and detect potential security issues across the application stack, including the database, Lambda functions, and frontend access patterns. Logs provide visibility into execution times, errors, and anomalies for ongoing optimization and security auditing.