从 DynamoDB 表生成云形成模板

Bod*_*dao 5 amazon-web-services

我有一个 DynamoDB 表需要复制到不同的环境。管理表的最佳方法是使用 CloudFormation 模板,以便脚本可以基于该模板创建表。鉴于该表已经存在,我想知道是否可以为现有表生成电子模板,有什么想法吗?google 没找到太多...

模板看起来像这样:

"Resources": {
    "CustomerTable": {
      "Type" : "AWS::DynamoDB::Table",
      "Properties" : {
        "KeySchema": [
          {
            "AttributeName": "customerId",
            "KeyType": "HASH"
          }
        ],
        "AttributeDefinitions": [
          {
            "AttributeName": "customerId",
            "AttributeType": "N"
          }
        ],
        "ProvisionedThroughput" : {
          "ReadCapacityUnits" : { "Ref": "CustomerReadCapacity" },
          "WriteCapacityUnits" : { "Ref": "CustomerWriteCapacity" }
        },
        "TableName" : "customer"
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

Mat*_*ser 6

您可以使用CloudFormer从 AWS 账户中的现有资源生成 CloudFormation 模板。

但是,生成的模板不会以任何方式链接到您的现有资源。CloudFormer 将生成一个模板,该模板是您现有资源的副本。使用生成的模板将使用新资源创建一个新的 CloudFormation 堆栈。

无法获取现有资源并将其包含在 CloudFormation 堆栈中。如果您希望您的资源由 CloudFormation 管理,那么它们首先需要由 CloudFormation 创建。

  • cloudFormer 使用起来很简单,但会让您跳过一些步骤(创建虚拟机、选择要导出的资源等)。一个更简单的解决方案(使用一些手动复制粘贴)是使用 aws CLI 的描述表获取表的布局(https://docs.aws.amazon.com/cli/latest/reference/dynamodb/describe-表.html)。然后,您可以保留所需的字段(AttributeDefinitions 等)并在它们周围放置一个 Cloudformation 骨架 (5认同)