AWSの公開しているDynamoDBのサンプルをServerless Frameworkで作ってみた😎

AWSの公開しているDynamoDBのサンプルをServerless Frameworkで作ってみた😎

参考ドキュメント

Serverless FrameworkのYamlコード

ProductCatalog:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: ProductCatalog
    AttributeDefinitions: 
      - AttributeName: Id
        AttributeType: N
    KeySchema:
      - AttributeName: Id
        KeyType: HASH
    ProvisionedThroughput:
      ReadCapacityUnits: 1
      WriteCapacityUnits: 1

Forum:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: Forum
    AttributeDefinitions:
      - AttributeName: Name
        AttributeType: S
    KeySchema:
      - AttributeName: Name
        KeyType: HASH
    ProvisionedThroughput:
      ReadCapacityUnits: 1
      WriteCapacityUnits: 1

Thread:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: Thread
    AttributeDefinitions:
      - AttributeName: ForumName
        AttributeType: S
      - AttributeName: Subject
        AttributeType: S
    KeySchema:
      - AttributeName: ForumName
        KeyType: HASH
      - AttributeName: Subject
        KeyType: RANGE
    ProvisionedThroughput:
      ReadCapacityUnits: 1
      WriteCapacityUnits: 1

Reply:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: Reply
    AttributeDefinitions:
      - AttributeName: Id
        AttributeType: S
      - AttributeName: ReplyDateTime
        AttributeType: S
      - AttributeName: PostedBy
        AttributeType: S
      - AttributeName: Message
        AttributeType: S
    KeySchema:
      - AttributeName: Id
        KeyType: HASH
      - AttributeName: ReplyDateTime
        KeyType: RANGE
    ProvisionedThroughput:
      ReadCapacityUnits: 1
      WriteCapacityUnits: 1
    GlobalSecondaryIndexes:
      - IndexName: PostedBy-Message-Index
        KeySchema:
          - AttributeName: PostedBy
            KeyType: HASH
          - AttributeName: Message
            KeyType: RANGE
        Projection:
          ProjectionType: ALL
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1

Serverless Frameworkについて思うこと

CloudFormationを非常に書きやすくしてくれますね。

クライアントワークで使用できなくても、アウトプットされたCloud Formationを提出すれば問題ないです。(そんなケースあまりありませんが)