DVA-C02 Question 35
Select 2You are developing an AWS Lambda function that processes images uploaded to an S3 bucket. The function should automatically trigger whenever a new image is uploaded to the bucket, and the processed results should be stored in another S3 bucket. Which of the following steps are required to accomplish this task?
- A
Create an S3 event notification on the source bucket to invoke the Lambda function when a new object is created.
- B
Assign an IAM role to the Lambda function with permissions to read from the source bucket and write to the destination bucket.
- C
Configure the Lambda function's runtime environment to include the AWS SDK for S3 interactions.
- D
Manually poll the source S3 bucket for new objects using a scheduled Lambda function invocation.
- E
Add a CloudWatch Events rule to trigger the Lambda function on object creation in the S3 bucket.
Show answer and explanation
Correct answers: A, B
Explanation
To process images uploaded to an S3 bucket with a Lambda function, you must configure an S3 event notification on the source bucket to trigger the Lambda function on object creation. Additionally, the Lambda function requires an IAM role with permissions to read from the source bucket and write to the destination bucket. Other options involve unnecessary or incorrect steps for this specific use case.
- A. Correct.
Correct: S3 event notifications are used to trigger a Lambda function when specific events (e.g., object creation) occur in a bucket. This is a core step for the task.
- B. Correct.
Correct: The Lambda function needs an IAM role with appropriate permissions to read from the source bucket and write to the destination bucket to perform its task.
- C. Incorrect.
Incorrect: The AWS SDK is pre-installed in the Lambda runtime environments (e.g., Node.js, Python), so explicitly including it is unnecessary.
- D. Incorrect.
Incorrect: Polling the S3 bucket manually using a scheduled invocation is inefficient and not required, as S3 provides event notification integration with Lambda.
- E. Incorrect.
Incorrect: CloudWatch Events rules are not used for triggering Lambda functions based on S3 events. Instead, S3 event notifications should be configured.