

# COST04-BP04 自動除役資源
<a name="cost_decomissioning_resources_decomm_automated"></a>

 設計工作負載，在識別和除役非關鍵資源、不需要的資源或低利用率資源時，妥善處理資源終止。 

 **未建立此最佳實務時的風險暴露等級：**低 

## 實作指引
<a name="implementation-guidance"></a>

使用自動化來降低或消除除役程序的相關成本。將工作負載設計為執行自動除役，可降低工作負載生命週期內的整體成本。您可以使用 [AWS Auto Scaling](https://aws.amazon.com/autoscaling/) 來執行除役程序。您也可以使用 [API 或 SDK](https://aws.amazon.com/developer/tools/) 實作自訂程式碼，自動除役工作負載資源。

 [現代化應用程式](https://aws.amazon.com/modern-apps/)會優先以無伺服器方式來建置，這個策略會優先採用無伺服器服務。AWS 針對下列三個堆疊層都開發了[無伺服器服務](https://aws.amazon.com/serverless/)：運算、整合和資料存放區。使用無伺服器架構可讓您透過自動縱向擴展和縮減規模，在低流量期間節省成本。 

**實作步驟**
+ **實作 AWS Auto Scaling：**對於受支援的資源，請使用 [AWS Auto Scaling](https://aws.amazon.com/autoscaling/) 來為其進行設定。AWS Auto Scaling 可以協助您在取用 AWS 服務時，獲得最佳的使用率和成本效率。當需求下降時，AWS Auto Scaling 會自動移除超額的資源容量，以免您超支。
+ **設定 CloudWatch 來終止執行個體：**執行個體可以設定為使用 [CloudWatch 警示加以終止](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/UsingAlarmActions.html#AddingTerminateActions)。使用來自於除役程序的指標，以 Amazon Elastic Compute Cloud 動作實作警示。推出之前，確認非生產環境中的操作。
+  **在工作負載內實作程式碼：**您可以使用 AWS SDK 或 AWS CLI 將工作負載資源除役。在整合 AWS 的應用程式內實作程式碼，並終止或移除不再使用的資源。
+  **使用無伺服器服務：**在 AWS 上優先建置[無伺服器架構](https://aws.amazon.com/serverless/)和[事件驅動架構](https://aws.amazon.com/event-driven-architecture/)，以建置和執行應用程式。AWS 提供了多個無伺服器技術服務，這些服務本身就會提供自動最佳化的資源使用率和自動化的除役 (縮減和橫向擴展)。在使用無伺服器應用程式時，系統會自動為您提供最佳化的資源使用率，您永遠不會因為過度佈建而支付費用。 

## 資源
<a name="resources"></a>

 **相關文件：** 
+  [AWS Auto Scaling](https://aws.amazon.com/autoscaling/) 
+  [AWS Trusted Advisor](https://aws.amazon.com/premiumsupport/trustedadvisor/) 
+  [AWS 上的無伺服器](https://aws.amazon.com/serverless/) 
+  [建立警示以停止、終止、重新啟動或復原執行個體](https://docs.aws.amazon.com/Amazon/latest/monitoring/UsingAlarmActions.html) 
+  [Amazon EC2 Auto Scaling 入門](https://docs.aws.amazon.com/autoscaling/ec2/userguide/GettingStartedTutorial.html) 
+  [在 Amazon CloudWatch 警示中新增終止動作](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/UsingAlarmActions.html#AddingTerminateActions) 

 **相關範例：** 
+  [排程自動刪除 AWS CloudFormation 堆疊](https://aws.amazon.com/blogs/infrastructure-and-automation/scheduling-automatic-deletion-of-aws-cloudformation-stacks/) 
+  [Well-Architected 實驗室：自動除役資源 (Level 100)](https://www.wellarchitectedlabs.com/cost/100_labs/100_goals_and_targets/4_decommission_resources/) 
+  [Servian AWS 自動清理](https://github.com/servian/aws-auto-cleanup) 