5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CloudFormationでDynamoDB streamを設定する

Posted at

前回の投稿【初心者向け】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コマンドを実行するだけ。素敵

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?