View a markdown version of this page

還原匯入操作 - AWS CloudFormation

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

還原匯入操作

如要還原匯入操作,請為您要從範本移除的資源指定 Retain 刪除政策,確保在您從堆疊刪除該資源時,仍會保留該資源。

使用 還原匯入操作 AWS 管理主控台

  1. 為您希望從堆疊移除的資源指定 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 } } } } }
  2. 開啟 CloudFormation 主控台來執行堆疊更新,以套用刪除政策。

    1. 在 Stacks (堆疊) 頁面上,選取堆疊、選擇 Update (更新),然後選擇 Update stack (standard) (更新堆疊 (標準))。

    2. 在 Prepare template (準備範本) 下方,選擇 Replace current template (取代目前範本)。

    3. 在 Specify template (指定範本) 下方,提供在 GamesTable 上具備 DeletionPolicy 屬性的更新來源範本,然後選擇 Next (下一步)。

      • 選擇 Amazon S3 URL,然後在文字方塊中指定指向更新後來源範本的 URL。

      • 選擇 Upload a template file (上傳範本檔案),然後瀏覽更新後的來源範本檔案。

    4. 在 Specify stack details (指定堆疊詳細資訊) 頁面上,不需要進行任何變更。選擇下一步。

    5. 在 Configure stack options (設定堆疊選項) 頁面上,不需要進行任何變更。選擇下一步。

    6. 在檢閱 stack_name 頁面上,檢閱您的變更。如果您的範本包含 IAM 資源,請選取 I acknowledge that this template may create IAM resources (我知道此範本可能會建立 IAM 資源),以指定您要使用此範本中的 IAM 資源。如需詳細資訊,請參閱認可 CloudFormation 範本中的 IAM 資源。然後,透過建立變更集合來更新來源堆疊,或直接更新來源堆疊。

  3. 從堆疊範本中移除資源、相關參數和輸出。在此範例中,範本現在看起來如下。

    範例 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 } } } } }
  4. 重複步驟 2,以從堆疊刪除資源 (GamesTable) 及其相關參數和輸出。

使用 還原匯入操作 AWS CLI

  1. 為您希望從堆疊移除的資源指定 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 } } } } }
  2. 更新堆疊,以將刪除政策套用到資源。

    aws cloudformation update-stack --stack-name MyStack
  3. 從堆疊範本中移除資源、相關參數和輸出。在此範例中,範本現在看起來如下。

    範例 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 } } } } }
  4. 更新堆疊以從堆疊刪除資源 (GamesTable) 及其相關參數和輸出。

    aws cloudformation update-stack --stack-name MyStack