サーバレス練習帳

着眼大局着手小局

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
}
)