amazon-web-services - Cloudformation DynamoDB 部署失败

标签 amazon-web-services yaml amazon-dynamodb aws-cloudformation

我有这个模板,非常简单。

DepartmentsTable:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: "Departments"
    AttributeDefinitions:
      - 
        AttributeName: "id"
        AttributeType: "S" 
      -
        AttributeName: "client_id"
        AttributeType: "S"
      -
        AttributeName: "department_name"
        AttributeType: "S"
    KeySchema:
      - 
        AttributeName: "id"
        KeyType: "HASH"
    BillingMode: "PAY_PER_REQUEST"

当我使用 3 个 attributeName 进行部署时,它不会部署。

当我将模板更改为具有单个属性时,它会进行部署。

任何想法

最佳答案

DynamoDB 是无模式的,因此在这方面您必须仅在创建时定义所需的键。

由于您仅使用 id 作为哈希键,因此这必须是您定义的唯一属性,因此您可以随意添加 client_iddepartment_name 当您插入您的元素时,CFN 不需要知道这些。这就是您收到异常的原因。

DepartmentsTable:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: "Departments"
    AttributeDefinitions:
      - 
        AttributeName: "id"
        AttributeType: "S" 
    KeySchema:
      - 
        AttributeName: "id"
        KeyType: "HASH"
    BillingMode: "PAY_PER_REQUEST"

更新:

AWSTemplateFormatVersion: "2010-09-09"
Resources: 
  MyTable:
    Type: AWS::DynamoDB::Table 
    Properties: 
      TableName: Departments 
      AttributeDefinitions: 
        - AttributeName: id 
          AttributeType: S 
        - AttributeName: sortKey 
          AttributeType: S 
      KeySchema: 
        - AttributeName: id 
          KeyType: HASH 
        - AttributeName: sortKey 
          KeyType: RANGE 
      ProvisionedThroughput: 
        ReadCapacityUnits: 1 
        WriteCapacityUnits: 1

关于amazon-web-services - Cloudformation DynamoDB 部署失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77051765/

相关文章:

amazon-web-services - 基于 Cognito token 的 AWS 节流

amazon-web-services - AWS Step Functions 中的 map 状态如何定价?

python - boto3 describe_load_balancers() 不显示任何内容,而 aws-cli 显示全部

perl - 为什么我必须加载 Perl 类才能使用我从 YAML 反序列化的对象?

amazon-web-services - AWS CloudFormation 的多个参数和输入 [SNS 主题]

amazon-web-services - 如何为多个 s3 对象创建一个 Glacier 存档?

Yaml 异常 : Unable to parse (near "apply_to: "\. CSS $"")

amazon-dynamodb - 是否可以使用 cognito-sync 将移动本地数据与一个中央 dynamodb 同步?

amazon-web-services - 断电后无法打开(本地 DynamoDB)数据库文件

amazon-dynamodb - 如何使用 boto3 使用 python 在 dynamo db 中建立连接