CloudFormationでDynamoDBテーブルをデプロイする – 【CloudFormation】
CloudFormationでDynamoDBテーブルをデプロイするyamlです。
DynamoDBテーブル(ソートキー無)
ソートキーはオプションなので省略します。
template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
DynamoDBTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: 'users'
AttributeDefinitions:
- AttributeName: 'userid'
AttributeType: 'S'
KeySchema:
- AttributeName: 'userid'
KeyType: 'HASH'
ProvisionedThroughput:
ReadCapacityUnits: '5'
WriteCapacityUnits: '5'
Outputs:
DynamoDBTableName:
Value: !Ref DynamoDBTable
Description: 'Table Name'
コマンドプロンプトでsam deployします。
sam deploy --template-file template.yaml --resolve-s3 ^ --stack-name stack-dynamodbtable --capabilities CAPABILITY_NAMED_IAM ^ --no-fail-on-empty-changeset --region ap-northeast-1
マネジメントコンソールからテーブルが作成されたことが確認できます。
DynamoDBテーブル(ソートキー有)
ソートキーも指定したSAMテンプレートです。
template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
DynamoDBTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: 'users'
AttributeDefinitions:
- AttributeName: 'userid'
AttributeType: 'S'
- AttributeName: 'joindate'
AttributeType: 'N'
KeySchema:
- AttributeName: 'userid'
KeyType: 'HASH'
- AttributeName: 'joindate'
KeyType: 'RANGE'
ProvisionedThroughput:
ReadCapacityUnits: '5'
WriteCapacityUnits: '5'
Outputs:
DynamoDBTableName:
Value: !Ref DynamoDBTable
Description: 'Table Name'
コマンドプロンプトでsam deployします。
sam deploy --template-file template.yaml --resolve-s3 ^ --stack-name stack-dynamodbtable --capabilities CAPABILITY_NAMED_IAM ^ --no-fail-on-empty-changeset --region ap-northeast-1
マネジメントコンソールからテーブルが作成されたことが確認できます。

KHI入社して退社。今はCONFRAGEで正社員です。関西で140-170/80~120万から受け付けております^^
得意技はJS(ES20xx),Java,AWSの大体のリソースです
コメントはやさしくお願いいたします^^
座右の銘は、「狭き門より入れ」「願わくは、我に七難八苦を与えたまえ」です^^



