From b92564d8d7eecb1663a04e93dfff042353ff8a69 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Sun, 2 Dec 2018 19:39:03 -0800 Subject: [PATCH] Add CloudFormation template for DynamoDB --- cf/podsync.yaml | 88 +++++++++++++++++++++++++++++++++++++++++++ pkg/storage/dynamo.go | 4 +- 2 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 cf/podsync.yaml diff --git a/cf/podsync.yaml b/cf/podsync.yaml new file mode 100644 index 0000000..70ff031 --- /dev/null +++ b/cf/podsync.yaml @@ -0,0 +1,88 @@ +AWSTemplateFormatVersion: "2010-09-09" +Parameters: + Prefix: + Type: String + Default: "Prod" + MinLength: 1 + Description: "Prefix to be added to all resources" +Outputs: + AccessKey: + Description: "DO user access key" + Value: !Ref DOUserKey + AccessSecret: + Description: "DO user secret key" + Value: !GetAtt DOUserKey.SecretAccessKey +Resources: + FeedsTable: + Type: AWS::DynamoDB::Table + Properties: + TableName: !Sub "${Prefix}_Feeds" + BillingMode: "PROVISIONED" + AttributeDefinitions: + - AttributeName: "HashID" + AttributeType: "S" + - AttributeName: "UserID" + AttributeType: "S" + - AttributeName: "CreatedAt" + AttributeType: "N" + KeySchema: + - AttributeName: "HashID" + KeyType: "HASH" + GlobalSecondaryIndexes: + - IndexName: "UserID-HashID-Index" + KeySchema: + - AttributeName: "UserID" + KeyType: "HASH" + - AttributeName: "CreatedAt" + KeyType: "RANGE" + Projection: + ProjectionType: "KEYS_ONLY" + ProvisionedThroughput: + ReadCapacityUnits: 1 + WriteCapacityUnits: 1 + ProvisionedThroughput: + ReadCapacityUnits: 10 + WriteCapacityUnits: 5 + TimeToLiveSpecification: + AttributeName: "ExpirationTime" + Enabled: true + PledgesTable: + Type: AWS::DynamoDB::Table + Properties: + TableName: !Sub "${Prefix}_Pledges" + BillingMode: "PROVISIONED" + AttributeDefinitions: + - AttributeName: "PatronID" + AttributeType: "N" + KeySchema: + - AttributeName: "PatronID" + KeyType: "HASH" + ProvisionedThroughput: + ReadCapacityUnits: 1 + WriteCapacityUnits: 1 + DOUser: + Type: AWS::IAM::User + DependsOn: + - FeedsTable + - PledgesTable + Properties: + Policies: + - PolicyName: "DynamoAccess" + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - "dynamodb:ListTables" + - "dynamodb:GetItem" + - "dynamodb:Query" + - "dynamodb:PutItem" + - "dynamodb:UpdateItem" + Resource: + - !GetAtt FeedsTable.Arn + - !GetAtt PledgesTable.Arn + DOUserKey: + Type: AWS::IAM::AccessKey + DependsOn: DOUser + Properties: + UserName: !Ref DOUser \ No newline at end of file diff --git a/pkg/storage/dynamo.go b/pkg/storage/dynamo.go index e539382..71ae560 100644 --- a/pkg/storage/dynamo.go +++ b/pkg/storage/dynamo.go @@ -47,11 +47,11 @@ Pledges: Feeds: Table name: Feeds Primary key: HashID (String) + RCU: 10 + WCU: 5 Secondary index: Primary key: UserID (String) Sort key: HashID (String) - RCU: 10 - WCU: 5 Index name: UserID-HashID-Index Projected attr: Keys only RCU/WCU: 1/1