DVA-C02 practice question 30 of 35

A developer wants to insert a record into an Amazon DynamoDB table as soon as a new file is added to an Amazon S3 bucket. Which set of steps would be necessary to achieve this?

Full set: 598 questions

Domain Development with AWS Services

Answer options
A: Create an event with Amazon EventBridge that will monitor the S3 bucket and then insert the records into DynamoDB.
B: Configure an S3 event to invoke an AWS Lambda function that inserts records into DynamoDB. Correct answer
C: Create an AWS Lambda function that will poll the S3 bucket and then insert the records into DynamoDB.
D: Create a cron job that will run at a scheduled time and insert the records into DynamoDB.
Correct Answer:
B. Configure an S3 event to invoke an AWS Lambda function that inserts records into DynamoDB.
Explanation

The most efficient and direct method to meet this requirement is using an event-driven, serverless architecture. Amazon S3 event notifications can be configured to trigger an AWS Lambda function automatically and in near-real time when a specific event occurs, such as an object creation (s3:ObjectCreated:). The Lambda function receives the event data, which includes details about the new S3 object. The function's code can then use the AWS SDK to process this information and write a new record to the specified Amazon DynamoDB table. This pattern is highly scalable, cost-effective, and avoids the latency and inefficiency of polling.

Why Incorrect

A. Amazon EventBridge can react to S3 events, but it cannot directly insert records into DynamoDB. It would still require a target, such as a Lambda function, to perform the database write, making this option less direct than B.
C. Polling an S3 bucket with a Lambda function is an inefficient anti-pattern. It introduces latency, as the function only runs on a schedule, and incurs unnecessary costs from repeated API calls to list bucket contents.
D. A cron job is a scheduled task, not an event-driven one. This approach would introduce a delay between the file upload and the database insert, failing to meet the "as soon as" requirement.

References

1. AWS Lambda Developer Guide, "Using AWS Lambda with Amazon S3": This document explicitly describes the pattern of using S3 to trigger a Lambda function. It states, "You can use Lambda to process event notifications from Amazon Simple Storage Service. Amazon S3 can send an event to a Lambda function when an object is created or deleted in a bucket." (Section: "Tutorial: Using an Amazon S3 trigger to invoke a Lambda function").

2. Amazon S3 User Guide, "Amazon S3 event notifications": This guide details how to configure notifications and lists AWS Lambda as a primary destination. "Amazon S3 event notifications can be sent to the following destinations: Amazon Simple Notification Service (Amazon SNS) topics, Amazon Simple Queue Service (Amazon SQS) queues, and AWS Lambda functions." (Section: "Event notification destinations").

3. AWS Lambda Developer Guide, "Tutorial: Using an Amazon S3 trigger to create thumbnail images": This official tutorial provides a step-by-step implementation of a nearly identical pattern (S3 trigger -> Lambda -> S3 write), which demonstrates the core principle of S3 event notifications invoking a Lambda function for processing. The same logic applies to writing to DynamoDB instead of S3.

Scroll to Top