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,通常作為前端接口,將請求路由到后端服務。