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

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

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

参考ドキュメント

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 を提出すれば問題ないです。(そんなケースあまりありませんが)

サーバーレス開発については、お気軽にお問い合わせください。