本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
還原匯入操作
如要還原匯入操作,請為您要從範本移除的資源指定 Retain
刪除政策,確保在您從堆疊刪除該資源時,仍會保留該資源。
使用 AWS Management Console還原匯入操作
-
Retain
DeletionPolicy 為您要從堆疊中移除的資源指定 。在以下範例範本中,GamesTable
是此還原操作的目標。範例 JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "Import test", "Resources": { "ServiceTable":{ "Type":"AWS::DynamoDB::Table", "Properties":{ "TableName":"Service", "AttributeDefinitions":[ { "AttributeName":"key", "AttributeType":"S" } ], "KeySchema":[ { "AttributeName":"key", "KeyType":"HASH" } ], "ProvisionedThroughput":{ "ReadCapacityUnits":5, "WriteCapacityUnits":1 } } }, "GamesTable": { "Type": "AWS::DynamoDB::Table", "DeletionPolicy": "Retain", "Properties": { "TableName": "Games", "AttributeDefinitions": [ { "AttributeName": "key", "AttributeType": "S" } ], "KeySchema": [ { "AttributeName": "key", "KeyType": "HASH" } ], "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 1 } } } } }
-
開啟 CloudFormation 主控台以執行堆疊更新,以套用刪除政策。
-
在 Stacks (堆疊) 頁面上,選取堆疊、選擇 Update (更新),然後選擇 Update stack (standard) (更新堆疊 (標準))。
-
在 Prepare template (準備範本) 下方,選擇 Replace current template (取代目前範本)。
-
在 Specify template (指定範本) 下方,提供在
GamesTable
上具備DeletionPolicy
屬性的更新來源範本,然後選擇 Next (下一步)。-
選擇 Amazon S3 URL,然後在文字方塊中將 指定URL為更新的來源範本。
-
選擇 Upload a template file (上傳範本檔案),然後瀏覽更新後的來源範本檔案。
-
-
在 Specify stack details (指定堆疊詳細資訊) 頁面上,不需要進行任何變更。選擇 Next (下一步)。
-
在 Configure stack options (設定堆疊選項) 頁面上,不需要進行任何變更。選擇 Next (下一步)。
-
在檢閱
MyStack
頁面上,檢閱您的變更。如果您的範本包含 IAM 資源,請選取 I acknowledge that this template may create IAM resources (我知道此範本可能會建立 IAM 資源),以指定您要使用此範本中的 IAM 資源。如需詳細資訊,請參閱確認 CloudFormation 範本中的 IAM 資源。然後,透過建立變更集合來更新來源堆疊,或直接更新來源堆疊。
-
-
從堆疊範本中移除資源、相關參數和輸出。在此範例中,範本現在看起來如下。
範例 JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "Import test", "Resources": { "ServiceTable":{ "Type":"AWS::DynamoDB::Table", "Properties":{ "TableName":"Service", "AttributeDefinitions":[ { "AttributeName":"key", "AttributeType":"S" } ], "KeySchema":[ { "AttributeName":"key", "KeyType":"HASH" } ], "ProvisionedThroughput":{ "ReadCapacityUnits":5, "WriteCapacityUnits":1 } } } } }
-
重複步驟 2,以從堆疊刪除資源 (
GamesTable
) 及其相關參數和輸出。
使用 AWS CLI還原匯入操作
-
Retain
DeletionPolicy 為您要從堆疊中移除的資源指定 。在以下範例範本中,GamesTable
是此還原操作的目標。範例 JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "Import test", "Resources": { "ServiceTable":{ "Type":"AWS::DynamoDB::Table", "Properties":{ "TableName":"Service", "AttributeDefinitions":[ { "AttributeName":"key", "AttributeType":"S" } ], "KeySchema":[ { "AttributeName":"key", "KeyType":"HASH" } ], "ProvisionedThroughput":{ "ReadCapacityUnits":5, "WriteCapacityUnits":1 } } }, "GamesTable": { "Type": "AWS::DynamoDB::Table", "DeletionPolicy": "Retain", "Properties": { "TableName": "Games", "AttributeDefinitions": [ { "AttributeName": "key", "AttributeType": "S" } ], "KeySchema": [ { "AttributeName": "key", "KeyType": "HASH" } ], "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 1 } } } } }
-
更新堆疊,以將刪除政策套用到資源。
aws cloudformation update-stack --stack-name
MyStack
-
從堆疊範本中移除資源、相關參數和輸出。在此範例中,範本現在看起來如下。
範例 JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "Import test", "Resources": { "ServiceTable":{ "Type":"AWS::DynamoDB::Table", "Properties":{ "TableName":"Service", "AttributeDefinitions":[ { "AttributeName":"key", "AttributeType":"S" } ], "KeySchema":[ { "AttributeName":"key", "KeyType":"HASH" } ], "ProvisionedThroughput":{ "ReadCapacityUnits":5, "WriteCapacityUnits":1 } } } } }
-
更新堆疊以從堆疊刪除資源 (
GamesTable
) 及其相關參數和輸出。aws cloudformation update-stack --stack-name
MyStack