You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

能否通过AWS CloudFormation模板一次性创建多个Amazon DynamoDB表?若可行,应采用多Properties还是多Resources方式?

Creating Multiple DynamoDB Tables in AWS CloudFormation

Absolutely, you can create multiple Amazon DynamoDB tables in a single CloudFormation template—this is a common use case and fully supported by AWS.

The Correct Approach: Multiple Resources Entries

To pull this off, you'll need to define separate Resources entries for each table, not multiple Properties within a single resource. Here's why:

  • In CloudFormation, each Resource block represents a distinct AWS resource. A DynamoDB table is its own standalone resource, so each table needs its own dedicated AWS::DynamoDB::Table resource definition.
  • The Properties section is specific to one resource—it defines configuration details (like schema, throughput, or encryption) for that individual resource. You can't pack multiple table configurations into a single Properties block; CloudFormation won't interpret that correctly and will throw validation errors.

Example Template with Two DynamoDB Tables

Here's a concrete, working example to illustrate how this structure looks:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  UsersTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: Users
      AttributeDefinitions:
        - AttributeName: UserID
          AttributeType: S
      KeySchema:
        - AttributeName: UserID
          KeyType: HASH
      ProvisionedThroughput:
        ReadCapacityUnits: 5
        WriteCapacityUnits: 5

  OrdersTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: Orders
      AttributeDefinitions:
        - AttributeName: OrderID
          AttributeType: S
        - AttributeName: UserID
          AttributeType: S
      KeySchema:
        - AttributeName: OrderID
          KeyType: HASH
        - AttributeName: UserID
          KeyType: RANGE
      ProvisionedThroughput:
        ReadCapacityUnits: 5
        WriteCapacityUnits: 5

In this template:

  • UsersTable and OrdersTable are unique logical IDs for each resource (you can name these whatever makes sense for your use case).
  • Each table has its own Properties block, where you define its specific schema, key structure, throughput, and any other custom settings.

Quick Recap

  • ✅ You can absolutely create multiple DynamoDB tables in one CloudFormation deployment.
  • ✅ Use separate Resources entries (one per table) with their own dedicated Properties configurations.
  • ❌ Avoid trying to cram multiple table settings into a single Resource's Properties—this isn't supported and will break your template.

内容的提问来源于stack exchange,提问作者Abhijith Nagarjuna

火山引擎 最新活动