恢复导入操作 - Amazon CloudFormation
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

恢复导入操作

要恢复导入操作,请为要从模板中删除的资源指定 Retain 删除策略,以确保从堆栈中删除时保留该资源。

使用 Amazon Web Services Management Console恢复导入操作

  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. 打开 Amazon 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 (指定堆栈详细信息) 页面上,不需要进行任何更改。选择 Next(下一步)。

    5. Configure stack options (配置堆栈选项) 页面上,不需要进行任何更改。选择 Next(下一步)。

    6. Review stack_name (查看 <堆栈名称>) 页面上,检查所做的更改。如果您的模板包含 IAM 资源,请选择 I acknowledge that this template may create IAM resources (我确认此模板可创建 IAM 资源) 以指定您要使用模板中的 IAM 资源。有关在模板中使用 IAM 资源的更多信息,请参阅使用 Amazon 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) 及其相关参数和输出。

使用 Amazon 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. 更新堆栈以将删除策略应用于资源。

    update-stack --stack-name "stack-name"
  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) 及其相关参数和输出。

    update-stack --stack-name "stack-name"