前回の投稿【初心者向け】CFnでAPI Gateway+LambdaなAPI作成をまとめてみた
に引き続きCloudFormationネタです
CFnでDynamoDB stream trigger eventを設定します
環境は
dev% aws --version
aws-cli/1.16.180 Python/3.7.3 Darwin/18.2.0 botocore/1.12.170
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
ストリームを設定するlambda
template.yaml
HogeFunction:
Type: AWS::Serverless::Function
Properties:
Timeout: 10
CodeUri: xxxxxxxxxx
Handler: app.lambdaHandler
Runtime: nodejs10.x
Role: !GetAtt LambdaRole.Arn
Events:
Stream:
Type: DynamoDB
Properties:
Stream: !GetAtt DataTable.StreamArn
BatchSize: 100
StartingPosition: LATEST
LambdaRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
Policies:
- PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- dynamodb:DescribeStream
- dynamodb:GetShardIterator
- dynamodb:GetRecords
- dynamodb:ListStreams
Resource: "*"
- Effect:
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: arn:aws:logs:*:*:*
これでcloudformationコマンドを実行するだけ。素敵