還原匯入操作 - AWS CloudFormation

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

還原匯入操作

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

使用 AWS Management Console還原匯入操作

  1. RetainDeletionPolicy為您要從堆疊中移除的資源指定一個。在以下範例範本中,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 控台以執行堆疊更新以套用刪除原則。

    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. 在 [檢MyStack] 頁面上,檢閱您的變更。如果您的範本包含 IAM 資源,請選取 I acknowledge that this template may create IAM resources (我知道此範本可能會建立 IAM 資源),以指定您要使用此範本中的 IAM 資源。如需有關使用範本中 IAM 資源的詳細資訊,請參閱控制存取 AWS Identity and Access Management。然後,透過建立變更集合來更新來源堆疊,或直接更新來源堆疊。

  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. RetainDeletionPolicy為您要從堆疊中移除的資源指定一個。在以下範例範本中,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