Optimal Solution for Triggering Lambda Function on New User Creation | AWS Certified Database - Specialty Exam

AWS Certified Database - Specialty: Optimal Solution for Triggering Lambda Function on New User Creation

Question

A photo-sharing application uses Amazon Aurora MySQL to store user data.

A development team would like to enhance the application by sending a welcome email every time a new user is created.

They've implemented an AWS Lambda function that will generate email text and send it using AWS SES.

What is the optimal solution for triggering the Lambda function when a new user is created?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer: B.

Option A is incorrect because this option requires application code change.

This is not an optimal solution.

Option B is CORRECT because Amazon Aurora MySQL mysql.lambda async function can be used within a stored procedure to invoke an AWS Lambda function.

The stored procedure can be triggered when a new user is created.

Option C is incorrect because it is not the easiest and most cost-efficient solution.

It consists of additional complexity involved with the configuration of Audit Log export and CloudWatch filters.

Additionally, there are costs associated with CloudWatch and S3 for log storage.

A simpler approach would be to use native MySQL capability to invoke the AWS Lambda function.

Therefore, this is not the optimal solution.

Option D is incorrect because audit logs are exported to CloudWatch.

Further, this is not an optimal solution as it involves complexity and costs associated with CloudTrail and SNS services.

Reference:

https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Integrating.Lambda.html

The optimal solution for triggering the Lambda function when a new user is created in Amazon Aurora MySQL depends on several factors such as scalability, performance, maintainability, and security.

Option A: Update the application code to invoke the AWS Lambda function when it inserts a new user in the Amazon Aurora database.

This option involves modifying the application code to call the Lambda function after inserting a new user into the Amazon Aurora database. Although it is a straightforward solution, it requires additional coding and maintenance efforts. Moreover, it may affect the application's performance and scalability if there are multiple concurrent database inserts. This option may not be the best solution for large-scale applications.

Option B: Create a trigger and stored procedure in the Amazon Aurora database. In the stored procedure, call mysql.lambda_async function to trigger the AWS Lambda function.

This option involves creating a trigger and stored procedure in the Amazon Aurora database that calls the mysql.lambda_async function to trigger the Lambda function. The trigger and stored procedure are executed automatically when a new user is inserted into the database, eliminating the need to modify the application code. This option is more efficient than Option A and suitable for large-scale applications that require high performance and scalability.

Option C: Configure Audit Log export on the Amazon Aurora database. Configure CloudWatch subscription filter to trigger the AWS Lambda function.

This option involves configuring the Audit Log export on the Amazon Aurora database to export database events to CloudWatch. Then, a subscription filter is set up in CloudWatch to trigger the Lambda function whenever a new user is created. This option is suitable for applications that require audit log export for compliance reasons. However, it may not be the best solution for triggering Lambda functions in real-time.

Option D: Configure Audit Log export on the Amazon Aurora database. Configure CloudTrail SNS notification. Create an AWS Lambda subscription to the SNS topic.

This option involves configuring the Audit Log export on the Amazon Aurora database to export database events to CloudTrail. Then, an SNS topic is created in CloudTrail, and a Lambda function is subscribed to the SNS topic. Whenever a new user is created, CloudTrail sends a notification to the SNS topic, which triggers the Lambda function. This option is suitable for applications that require real-time notifications and event-driven architectures. However, it requires additional setup and may add complexity to the system.

In conclusion, Option B is the optimal solution for triggering the Lambda function when a new user is created in Amazon Aurora MySQL. It provides high performance and scalability, eliminates the need for application code modification, and is suitable for large-scale applications. However, other options may be suitable depending on specific requirements such as audit logging and real-time notifications.