はじめに
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