考题解析 | 使用 Amazon SQS 和 AWS Lambda自动化处理用户上传的图片


  题目

An application development team is designing a microservice that will convert large images to smaller, compressed images. When a user uploads an image through the web interface, the microservice should store the image in an Amazon S3 bucket, process and compress the image with an AWS Lambda function, and store the image in its compressed form in a different S3 bucket.
A solutions architect needs to design a solution that uses durable, stateless components to process the images automatically. Which combination of actions will meet these requirements? (Choose two.)
A. Create an Amazon Simple Queue Service (Amazon SQS) queue. Configure the S3 bucket to send a notification to the SQS queue when an image is uploaded to the S3 bucket.
B. Configure the Lambda function to use the Amazon Simple Queue Service (Amazon SQS) queue as the invocation source. When the SQS message is successfully processed, delete the message in the queue.
C. Configure the Lambda function to monitor the S3 bucket for new uploads. When an uploaded image is detected, write the file name to a text file in memory and use the text file to keep track of the images that were processed.
D. Launch an Amazon EC2 instance to monitor an Amazon Simple Queue Service (Amazon SQS) queue. When items are added to the queue, log the file name in a text file on the EC2 instance and invoke the Lambda function.
E. Configure an Amazon EventBridge (Amazon CloudWatch Events) event to monitor the S3 bucket. When an image is uploaded, send an alert to an Amazon ample Notification Service (Amazon SNS) topic with the application owner's email address for further processing.

  参考答案

AB

  参考解析

技巧:排除明显错误选项,在没有明显错误的选项中选择最合理的选项。
一个应用开发团队正在设计一个微服务,该服务将大型图像转换为较小、压缩后的图像。当用户通过网页界面上传图像时,微服务应将图像存储在 Amazon S3 存储桶中,使用 AWS Lambda 函数处理和压缩图像,并将压缩后的图像存储在另一个 S3 存储桶中。解决方案架构师需要设计一个使用持久、无状态组件的解决方案,以自动处理图像。
推荐方案,通过SQS队列实现事件的异步和持久处理,然后配置Lambda函数从SQS队列中读取和处理消息,实现无状态的处理流程。

A. 正确。创建一个 Amazon Simple Queue Service(Amazon SQS)队列。配置 S3 存储桶,当图像上传到 S3 存储桶时,向 SQS 队列发送通知。通过配置 S3 存储桶在图像上传时发送通知到 SQS 队列,可以实现事件的异步处理。SQS 队列作为一个持久、可靠的消息传递服务,可以确保事件不会丢失,并且可以被 Lambda 函数按需处理。
B. 正确。配置 Lambda 函数使用 Amazon Simple Queue Service(Amazon SQS)队列作为调用源。当 SQS 消息成功处理后,删除队列中的消息。Lambda 函数可以配置为从 SQS 队列中读取消息,并处理这些消息。处理成功后,Lambda 函数会自动删除队列中的消息,确保消息不会被重复处理。这种配置实现了无状态的处理,因为 Lambda 函数不需要维护任何关于已处理消息的状态。
C. 不正确。配置 Lambda 函数监控 S3 存储桶的新上传。当检测到上传的图像时,将文件名写入内存中的文本文件,并使用该文本文件跟踪已处理的图像。Lambda 函数是无状态的,且其执行环境在每次调用后都可能被回收,因此不能依赖内存中的文本文件来跟踪已处理的图像。此外,这种方法也不具备持久性,因为内存中的数据在 Lambda 函数执行结束后可能会丢失。
D. 不正确。启动一个 Amazon EC2 实例来监控 Amazon Simple Queue Service(Amazon SQS)队列。当项目被添加到队列中时,在 EC2 实例上的文本文件中记录文件名,并调用 Lambda 函数。引入 EC2 实例增加了系统的复杂性和运维成本,而且 EC2 实例是有状态的,需要维护和管理。此外,使用 EC2 实例来监控 SQS 队列并调用 Lambda 函数是一种不必要的冗余,因为 Lambda 函数本身就可以直接从 SQS 队列中读取和处理消息。
E. 不正确。配置一个 Amazon EventBridge(Amazon CloudWatch Events)事件来监控 S3 存储桶。当图像上传时,向包含应用程序所有者电子邮件地址的 Amazon Simple Notification Service(Amazon SNS)主题发送警报,以进行进一步处理。EventBridge(CloudWatch Events)可以用于监控 S3 存储桶的事件,但发送 SNS 警报并不是自动处理图像的有效方法。SNS 主要用于通知和警报,而不是作为事件处理流程的一部分。