2017-07-10 7 views
0

コマンドラインまたはオンラインAPIから、「複合プライマリキー」を作成するのに問題はありませんが、CloudFormationを使用して私の仕事をしようとすると、 「複合主キー」と呼ばれるものを設定できるJSON/YAMLを参照してください。言葉はまったく違うので、誰かが私がCloudFormを使ってどのようにそのような鍵を作成するかについて私を導くことができればと願っていました。コンポジットプライマリキーを使用してCloudoを使用してDynamoDBを作成する

ここ
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 
+0

複合主キーを使用してテーブルを作成するコマンドを表示できますか? – notionquest

+0

正しいYAML構文が必要です。私は実際にサーバーレスのフレームワークを使ってクラウドフォーメーションコードを展開しています。 Web APIにはチェックする簡単なボックスがあります。 – user985030

答えて

2

がパーティションを持つDynamoDBのテーブル作成のためのYAML構文で、キーを並べ替える:

私の最高の推測では、私は複合キーは、ユーザーIDとのnoteId両方で構成したい、次のようなものです。

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" 
関連する問題