サーバレス練習帳

着眼大局着手小局

忘れちゃいけない設定集

API-GWは「統合」にチェック。

DynamoからLambdaへのトリガはバッチサイズを1にしましょう。

Dynamoのストリームを一回無効にしてから有効化。そのときに新規イメージのみを選択する。

Lambdaをタイムアウトさせてしまうと、Dynamoがトリガをリトライしてしまうので、タイムアウトさせる前に正常終了させよう。

Dynamo+Lambdaの開始位置とは?

dev.classmethod.jp

 

Dynamo DBトリガの水平トリムか?最新か?の話です。

 

(引用)

Starting Position」というのは読み取りを開始する位置を表します「Latest(最新のものから順番に読み取る)」と「Trim horizon(読み取りされていないものを古い順から読み取る)」の2種類から選択します。時間順にデータを処理するならTrim horizon、最新のデータを使用する設計ならLatestを選びましょう。

 

Boto3でDynamoテーブル作成

import boto3

# Get the service resource.
dynamodb = boto3.resource('dynamodb')


def lambda_handler(event, context):
# Create the DynamoDB table.
table = dynamodb.create_table(
TableName='LineData',
KeySchema=[
{
'AttributeName': 'UserId',
'KeyType': 'HASH'
},
{
'AttributeName': 'MessageId',
'KeyType': 'RANGE'
}
],
AttributeDefinitions=[
{
'AttributeName': 'UserId',
'AttributeType': 'S'
},
{
'AttributeName': 'MessageId',
'AttributeType': 'N'
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
}
)