Skip to content

Commit

Permalink
feat(storage): Add dynamoDB Cloudformation templates (#993)
Browse files Browse the repository at this point in the history
<!-- Provide summary of changes -->
This PR adds the cloudformation template necessary to create DDB tables on behalf of customers in storage init. 

<!-- Issue number, if available. E.g. "Fixes #31", "Addresses #42, 77" -->
Addresses #769 

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
  • Loading branch information
bvtujo authored Jun 4, 2020
1 parent 5b87893 commit 098e612
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
23 changes: 23 additions & 0 deletions templates/addons/ddb/cf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{.TableResourceName}}:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
Properties:
TableName: !Sub ${App}-${Env}-${Name}-{{.TableName}}
AttributeDefinitions:
- AttributeName: {{.Name}}
AttributeType: "{{.DataType}}"{{end}}
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: {{.PartitionKey}}
KeyType: HASH{{ if .SortKey }}
- AttributeName: {{.SortKey}}
KeyType: RANGE{{end}}{{if .HasLSI}}
LocalSecondaryIndexes:{{range .LSIs}}
- IndexName: {{.Name}}
KeySchema:
- AttributeName: {{.PartitionKey}}
KeyType: HASH
- AttributeName: {{.SortKey}}
KeyType: RANGE
Projection:
ProjectionType: ALL{{end}}{{end}}
6 changes: 6 additions & 0 deletions templates/addons/ddb/outputs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{.TableResourceName}}TableName:
Description: "The name of this DynamoDB."
Value: !Ref {{.TableResourceName}}
{{.TableResourceName}}AccessPolicy:
Description: "The IAM::ManagedPolicy to attach to the task role."
Value: !Ref {{.TableResourceName}}AccessPolicy
30 changes: 30 additions & 0 deletions templates/addons/ddb/policy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{.TableResourceName}}AccessPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
Description: !Sub
- Grants CRUD access to the Dynamo DB table ${Table}
- { Table: !Ref {{.TableResourceName}} }
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: DDBActions
Effect: Allow
Action:
- dynamodb:BatchGet*
- dynamodb:DescribeStream
- dynamodb:DescribeTable
- dynamodb:Get*
- dynamodb:Query
- dynamodb:Scan
- dynamodb:BatchWrite*
- dynamodb:Create*
- dynamodb:Delete*
- dynamodb:Update*
- dynamodb:PutItem
Resource: !Sub ${ {{.TableResourceName}}.Arn}
- Sid: DDBLSIActions
Action:
- dynamodb:Query
- dynamodb:Scan
Effect: Allow
Resource: !Sub ${ {{.TableResourceName}}.Arn}/Index/*

0 comments on commit 098e612

Please sign in to comment.