使用Cloudformation创建具有复合主键的DynamoDB

use*_*030 3 aws-cloudformation amazon-dynamodb

从命令行或在线API,我可以轻松创建"复合主键",但当我尝试使用CloudFormation为我完成工作时,我没有看到任何JSON/YAML会让我设置一个名为"复合主键".语言完全不同,所以我希望有人可以指导我如何使用Cloudformation创建这样的密钥.

我最好的猜测是如下所示,我希望复合键包含userId和noteId:

  Resources:
    usersTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: notes_serverless
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: noteId
            AttributeType: S
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: noteId
            KeyType: RANGE
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
Run Code Online (Sandbox Code Playgroud)

not*_*est 9

以下是使用分区和排序键创建DynamoDB表的YAML语法.

OP上的语法几乎是正确的.我刚刚用适当的引号格式化并重新排列属性的顺序.

AWSTemplateFormatVersion: "2010-09-09"
Resources: 
  usersTable: 
    Type: "AWS::DynamoDB::Table"
    Properties: 
      AttributeDefinitions: 
        - 
          AttributeName: "userId"
          AttributeType: "S"
        - 
          AttributeName: "noteId"
          AttributeType: "S"
      KeySchema: 
        - 
          AttributeName: "userId"
          KeyType: "HASH"
        - 
          AttributeName: "noteId"
          KeyType: "RANGE"
      ProvisionedThroughput: 
        ReadCapacityUnits: "5"
        WriteCapacityUnits: "5"
      TableName: "notes_serverless"
Run Code Online (Sandbox Code Playgroud)