A company uses an AWS Batch job to run its end-of-day sales process. The company needs a serverless solution that will invoke a third-party reporting application when the AWS Batch job is successful. The reporting application has an HTTP API interface that uses username and password authentication.
Which solution will meet these requirements?
A. Configure an Amazon EventBridge rule to match incoming AWS Batch job SUCCEEDED events. Configure the third-party API as an EventBridge API destination with a username and password. Set the API destination as the EventBridge rule target.
B. Configure Amazon EventBridge Scheduler to match incoming AWS Batch job SUCCEEDED events. Configure an AWS Lambda function to invoke the third-party API by using a username and password. Set the Lambda function as the EventBridge rule target.
C. Configure an AWS Batch job to publish job SUCCEEDED events to an Amazon API Gateway REST API. Configure an HTTP proxy integration on the API Gateway REST API to invoke the third-party API by using a username and password.
D. Configure an AWS Batch job to publish job SUCCEEDED events to an Amazon API Gateway REST API. Configure a proxy integration on the API Gateway REST API to an AWS Lambda function. Configure the Lambda function to invoke the thirdparty API by using a username and password.
A
一家公司使用 AWS Batch 作业来运行其每日销售结束处理流程。该公司需要一个无服务器解决方案,以便在 AWS Batch 作业成功完成后调用第三方报表应用程序。该报表应用程序具有一个使用用户名和密码进行身份验证的 HTTP API 接口。哪种解决方案能满足这些要求?核心问题是要找到一个无服务器解决方案,在 AWS Batch 作业成功时触发调用具有用户名和密码身份验证的 HTTP API 接口的第三方报表应用程序。关键在于利用无服务器组件实现事件触发和 API 调用,同时满足身份验证需求。
技巧:排除明显错误选项,在没有明显错误的选项中选择最合理的选项。
A. 正确。配置一个 Amazon EventBridge 规则以匹配传入的 AWS Batch 作业成功事件。将第三方 API 配置为 EventBridge API 目标,并设置用户名和密码。将该 API 目标设置为 EventBridge 规则的目标。该方案利用 EventBridge 捕获 Batch 作业成功事件,并且 EventBridge 支持直接将外部 API 配置为目标,能在规则匹配事件时直接调用第三方 API,同时支持在配置 API 目标时设置用户名和密码进行身份验证,完全满足无服务器触发和调用带身份验证 API 的要求,是可行的方案。
B. 不正确。配置 Amazon EventBridge Scheduler 以匹配传入的 AWS Batch 作业成功事件。配置一个 AWS Lambda 函数,使用用户名和密码调用第三方 API。将该 Lambda 函数设置为 EventBridge 规则的目标。EventBridge Scheduler 主要侧重于计划任务,不是专门用于捕获实时事件(如 Batch 作业成功事件)的最佳工具。通常应使用 Amazon EventBridge 来捕获此类事件,所以该方案在事件触发机制选择上不合适,不满足要求。
C. 不正确。配置 AWS Batch 作业将作业成功事件发布到 Amazon API Gateway REST API。在 API Gateway REST API 上配置 HTTP 代理集成,使用用户名和密码调用第三方 API。让 AWS Batch 作业直接发布事件到 API Gateway 不是常见的做法,Batch 作业本身不具备直接与 API Gateway 交互发布事件的功能,实现起来复杂且不符合常规架构设计。通常使用 EventBridge 等事件总线服务来捕获和处理事件,所以该方案不可行。
D. 不正确。配置 AWS Batch 作业将作业成功事件发布到 Amazon API Gateway REST API。在 API Gateway REST API 上配置到 AWS Lambda 函数的代理集成。配置 Lambda 函数使用用户名和密码调用第三方 API。该方案与选项 C 类似,让 Batch 作业直接发布事件到 API Gateway 不合理且难以实现。而且此方案引入了不必要的复杂层级,使用 EventBridge 直接捕获事件并调用 API 或 Lambda 函数更为简洁高效,所以该方案也不符合要求。
事件触发:需要一种机制来捕获 AWS Batch 作业成功完成的事件,并基于此事件触发后续操作。AWS 提供了相关服务来处理事件,如 Amazon EventBridge 等。
无服务器调用 API:要实现无服务器方式调用第三方 API,可借助 AWS Lambda 函数(它能在无需管理服务器的情况下运行代码)或者利用特定服务直接与 API 交互。同时,需要处理用户名和密码的身份验证,这通常在调用 API 时通过合适的请求头或参数传递。
Amazon EventBridge:可用于构建事件驱动的应用程序,能捕获各种 AWS 服务的事件,并根据规则将事件路由到目标。它支持 API 目标,可直接与外部 API 交互。
Amazon EventBridge Scheduler:主要用于在指定时间或按计划运行任务,虽然也能处理事件,但相比 EventBridge 在事件路由和与外部 API 直接交互方面功能侧重不同。
AWS Lambda:可编写代码来处理事件并调用第三方 API,能灵活处理身份验证等逻辑。
Amazon API Gateway:主要用于创建、部署和管理 API,通常作为前端接口,将请求路由到后端服务。