考题解析 | 将大量小文件上传到 Amazon S3 上并执行自动化处理


  题目

A company is designing an application where users upload small files into Amazon S3. After a user uploads a file, the file requires one-time simple processing to transform the data and save the data in JSON format for later analysis. Each file must be processed as quickly as possible after it is uploaded. Demand will vary. On some days, users will upload a high number of files. On other days, users will upload a few files or no files.
Which solution meets these requirements with the LEAST operational overhead?
A. Configure Amazon EMR to read text files from Amazon S3. Run processing scripts to transform the data. Store the resulting JSON file in an Amazon Aurora DB cluster.
B. Configure Amazon S3 to send an event notification to an Amazon Simple Queue Service (Amazon SQS) queue. Use Amazon EC2 instances to read from the queue and process the data. Store the resulting JSON file in Amazon DynamoDB.
C. Configure Amazon S3 to send an event notification to an Amazon Simple Queue Service (Amazon SQS) queue. Use an AWS Lambda function to read from the queue and process the data. Store the resulting JSON file in Amazon DynamoDB.
D. Configure Amazon EventBridge (Amazon CloudWatch Events) to send an event to Amazon Kinesis Data Streams when a new file is uploaded. Use an AWS Lambda function to consume the event from the stream and process the data. Store the resulting JSON file in an Amazon Aurora DB cluster.

  参考答案

C

  需求概括

一家公司正在设计一个应用程序,用户将小文件上传到Amazon S3。用户上传文件后,该文件需要进行一次性简单处理以转换数据,并将数据以JSON格式保存以供后续分析。每个文件上传后必须尽快处理。需求会有所变化。某些天用户会上传大量文件。其他日子用户可能只上传少量文件或不上传。
本题要求设计一个解决方案,用于处理用户上传到Amazon S3的小文件,进行简单数据处理并存储为JSON格式,需满足文件上传后尽快处理,且能应对不同上传量的情况,同时要求运营开销最小。

  技术总结

本题关键在于选择一种能够根据文件上传量自动扩展处理能力,且运营管理简单的架构。需要考虑事件触发机制、处理逻辑的执行方式以及数据存储的合适选择。

  参考解析

技巧:排除明显错误选项,在没有明显错误的选项中选择最合理的选项。

A. 不正确。配置Amazon EMR从Amazon S3读取文本文件。运行处理脚本转换数据。将生成的JSON文件存储在Amazon Aurora数据库集群中。Amazon EMR主要用于大规模数据处理,通常用于处理大量数据的复杂场景。对于这种小文件的一次性简单处理,使用EMR过于复杂,成本较高,且运营管理难度大,不符合最小运营开销的要求。
B. 不正确。配置Amazon S3向Amazon Simple Queue Service(Amazon SQS)队列发送事件通知。使用Amazon EC2实例从队列读取数据并进行处理。将生成的JSON文件存储在Amazon DynamoDB中。使用EC2实例需要手动管理实例的启动、停止和扩展,以应对不同的文件上传量。这增加了运营管理的复杂性,并且当文件上传量较少时,EC2实例可能闲置,造成资源浪费,运营开销较大。
C. 正确。配置Amazon S3向Amazon Simple Queue Service(Amazon SQS)队列发送事件通知。使用AWS Lambda函数从队列读取数据并进行处理。将生成的JSON文件存储在Amazon DynamoDB中。当文件上传到S3时,S3可以触发事件通知到SQS队列。Lambda函数作为无服务器计算服务,可以根据队列中的消息自动触发并扩展,无需手动管理服务器。处理完成后,将结果存储在DynamoDB中,DynamoDB是一种无服务器数据库,也能自动扩展。这种方案能够很好地应对不同的文件上传量,且运营开销最小。
D. 不正确。配置Amazon EventBridge(Amazon CloudWatch Events)在上传新文件时向Amazon Kinesis Data Streams发送事件。使用AWS Lambda函数从流中消费事件并处理数据。将生成的JSON文件存储在Amazon Aurora数据库集群中。虽然Lambda函数可以自动扩展,但Kinesis Data Streams主要用于实时数据流处理,对于这种小文件的简单处理场景,引入Kinesis Data Streams增加了架构的复杂性,运营管理难度较大,且成本可能较高。