A production account has a requirement that any Amazon EC2 instance that has been logged into manually must be terminated within 24 hours. All applications in the production account are using Auto Scaling groups with Amazon CloudWatch Logs agent configured.
How can this process be automated?
A. Create a CloudWatch Logs subscription to an AWS Step Functions application. Configure the function to add a tag to the EC2 instance that produced the login event and mark the instance to be decommissioned. Then create a CloudWatch Events rule to trigger a second AWS Lambda function once a day that will terminate all instances with this tag.
B. Create a CloudWatch alarm that will trigger on the login event. Send the notification to an Amazon SNS topic that the operations team is subscribed to, and have them terminate the EC2 instance within 24 hours.
C. Create a CloudWatch alarm that will trigger on the login event. Configure the alarm to send to an Amazon SQS queue. Use a group of worker instances to process messages from the queue, which then schedules the Amazon CloudWatch Events rule to trigger.
D. Create a CloudWatch Logs subscription in an AWS Lambda function. Configure the function to add a tag to the EC2 instance that produced the login event and mark the instance to be decommissioned. Create a CloudWatch Events rule to trigger a daily Lambda function that terminates all instances with this tag.
D
技巧:排除明顯錯(cuò)誤選項(xiàng),在沒有明顯錯(cuò)誤的選項(xiàng)中選擇最合理的選項(xiàng)。
題目要求自動化終止在24小時(shí)內(nèi)被手動登錄的Amazon EC2實(shí)例。需要提供一個(gè)解決方案,能夠?qū)崟r(shí)檢測登錄事件、標(biāo)記實(shí)例并在24小時(shí)內(nèi)終止這些實(shí)例。
A. 不正確。這個(gè)選項(xiàng)使用AWS Step Functions來管理一系列操作,但 AWS Step Functions主要用于協(xié)調(diào)多個(gè)AWS服務(wù)之間的復(fù)雜的、有狀態(tài)的工作流,不是處理簡單標(biāo)記和終止任務(wù)的最佳選擇。另外該選項(xiàng)依賴于每日運(yùn)行一次的Lambda函數(shù)來終止標(biāo)記的實(shí)例,每日檢查并終止這些實(shí)例的方法不夠及時(shí),這不符合24小時(shí)內(nèi)的要求
B. 不正確。使用 Amazon SNS 和 CloudWatch Alarm 服務(wù)。這個(gè)選項(xiàng)依賴于手動操作,因?yàn)镾NS通知只是警告操作團(tuán)隊(duì),并沒有自動終止實(shí)例。這不符合自動化要求,因?yàn)樗蕾囉谌藶楦深A(yù)。
C. 不正確。使用Amazon SQS、CloudWatch Alarms、CloudWatch events 和Worker Instances 服務(wù)。這個(gè)選項(xiàng)引入了一個(gè)額外的消息隊(duì)列(SQS)和一組worker實(shí)例來處理消息,這增加了系統(tǒng)的復(fù)雜性。使用 worker 實(shí)例和 CloudWatch Events 規(guī)則來觸發(fā)終止操作也不是最直接的解決方案,并且同樣沒有保證在24小時(shí)內(nèi)完成。
D. 正確。使用 AWS Lambda 和 CloudWatch Logs 服務(wù)。該選項(xiàng)創(chuàng)建一個(gè) CloudWatch Logs訂閱,該訂閱將日志事件發(fā)送到AWS Lambda函數(shù)。Lambda 函數(shù)可以立即響應(yīng)登錄事件,為產(chǎn)生該事件的EC2實(shí)例添加一個(gè)特定的標(biāo)簽;同時(shí)創(chuàng)建一個(gè) CloudWatch Events 規(guī)則,該規(guī)則每隔一段時(shí)間(例如每小時(shí))檢查是否有帶有特定標(biāo)簽的實(shí)例存在,并觸發(fā)另一個(gè)Lambda函數(shù)來終止這些實(shí)例。這種方法最大可能地確保了實(shí)例在被登錄后的24小時(shí)內(nèi)能夠被終止。