DVA-C02 Question 361
Single answerYou are developing a serverless application that uses AWS Lambda to process data from an Amazon S3 bucket. The application must ensure that Lambda is triggered whenever a specific S3 bucket receives a new object. What is the best way to configure this integration?
- A
Create an EventBridge rule to monitor the S3 bucket and invoke the Lambda function.
- B
Configure an S3 Event Notification on the bucket to trigger the Lambda function.
- C
Write a custom polling mechanism in the Lambda function to check the S3 bucket for new objects.
- D
Manually invoke the Lambda function whenever a new object is uploaded to the S3 bucket.
Show answer and explanation
Correct answer: B
Explanation
The best way to trigger a Lambda function when a new object is added to an S3 bucket is to use the native S3 Event Notifications feature. This allows you to configure the S3 bucket to automatically invoke the Lambda function upon specific events (e.g., object creation). This approach is efficient, automated, and aligns well with serverless best practices.
- A. Incorrect.
EventBridge is not the recommended approach for direct S3-to-Lambda integration. While EventBridge can monitor S3 events, it adds unnecessary complexity for this use case.
- B. Correct.
An S3 Event Notification is the correct way to trigger a Lambda function when a new object is added to the bucket. This is a native integration between S3 and Lambda.
- C. Incorrect.
Using a custom polling mechanism is inefficient and not scalable. AWS offers native services like S3 Event Notifications to handle such use cases.
- D. Incorrect.
Manually invoking the Lambda function is impractical and defeats the purpose of an automated serverless architecture.