DVA-C02 Question 282
Single answerYou are developing a serverless application using AWS Lambda and need to integrate it with an Amazon S3 bucket to process uploaded files. The Lambda function must be triggered automatically whenever a new file is added to the bucket. How can you achieve this functionality?
- A
Configure an S3 event notification on the bucket to invoke the Lambda function when an object is created.
- B
Set up a CloudWatch Events rule to monitor the S3 bucket and invoke the Lambda function for every file upload.
- C
Use the AWS SDK to periodically poll the S3 bucket from the Lambda function for newly uploaded files.
- D
Enable versioning on the S3 bucket and configure it to trigger the Lambda function for each new version of an object.
Show answer and explanation
Correct answer: A
Explanation
The best way to integrate an Amazon S3 bucket with a Lambda function is by configuring S3 event notifications. This allows the bucket to invoke the Lambda function automatically whenever a specific event, such as an object creation, occurs. This is an efficient and serverless approach to achieving the required functionality.
- A. Correct.
Correct. Amazon S3 supports event notifications, which can be configured to invoke a Lambda function whenever an object is created in the bucket.
- B. Incorrect.
Incorrect. CloudWatch Events is not designed to monitor S3 bucket events directly; S3 event notifications are the appropriate mechanism.
- C. Incorrect.
Incorrect. Polling the bucket is not an efficient or recommended approach when S3 event notifications can provide real-time triggering.
- D. Incorrect.
Incorrect. While enabling versioning is useful for object version control, it is not required to trigger Lambda functions for new object uploads.