DVA-C02 Question 7
Select 3You are developing a serverless application using AWS Lambda and Amazon S3. Your application processes images uploaded to an S3 bucket by resizing them. You want to ensure the Lambda function is triggered automatically each time a new image is uploaded. Which of the following steps do you need to take to achieve this?
- A
Create an S3 event notification on the bucket and configure it to trigger your Lambda function.
- B
Grant the S3 bucket permission to invoke the Lambda function by adding the appropriate permissions to the bucket policy.
- C
Add a trigger for the S3 bucket in the Lambda function configuration.
- D
Ensure the Lambda function has an execution role with permissions to access the S3 bucket.
- E
Enable versioning on the S3 bucket to allow Lambda to process events reliably.
Show answer and explanation
Correct answers: A, C, D
Explanation
To automatically trigger a Lambda function when a new image is uploaded to an S3 bucket, you need to configure an S3 event notification on the bucket, add the bucket as a trigger in the Lambda function configuration, and ensure the Lambda function has an execution role with appropriate permissions. Adding permissions to the S3 bucket or enabling versioning is not necessary for this use case.
- A. Correct.
This step is correct and required. S3 event notifications allow you to configure a bucket to trigger a Lambda function when specific events occur, such as object creation.
- B. Incorrect.
This is incorrect. The S3 bucket does not need permissions to invoke the Lambda function; instead, the Lambda function needs permissions to interact with the S3 bucket.
- C. Correct.
This step is correct. You need to add a trigger to associate the S3 bucket with the Lambda function so that the function is invoked on relevant events.
- D. Correct.
This step is correct. The Lambda function requires an execution role with permissions (e.g.,
s3:GetObject) to access the S3 bucket and process the objects. - E. Incorrect.
This is incorrect. While versioning is useful for data integrity and recovery, it is not required for setting up S3 event notifications or triggering a Lambda function.