LoginSignup
1
0

AWS SAMでDynamoDB使う時のテンプレート

Posted at

はじめに

SAM template使う時、DynamoDBの定義に関して毎回調べてる気がするのでここに残しておきます。

コード

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  description

Globals:
  Function:
    Timeout: 30
    MemorySize: 128

Resources:
  SomeFunction:
    Type: AWS::Serverless::Function
    Metadata:
      BuildMethod: go1.x
    Properties:
      CodeUri: some_function/
      Handler: bootstrap
      Runtime: provided.al2
      Architectures:
        - x86_64
      Policies:
        - DynamoDBCrudPolicy:
            TableName: !Ref SampleTable
      Environment:
        Variables:
          SAMPLE_TABLE: !Ref SampleTable

  SampleTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: 'SampleTable'
      AttributeDefinitions:
        - AttributeName: 'id'
          AttributeType: 'S'
        - AttributeName: 'value'
          AttributeType: 'N'
      KeySchema:
        - AttributeName: 'id'
          KeyType: 'HASH'
        - AttributeName: 'value'
          KeyType: 'RANGE'
      BillingMode: PAY_PER_REQUEST

Outputs:
  SomeFunction:
    Description: "First Lambda Function ARN"
    Value: !GetAtt SomeFunction.Arn
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0