ddb.yaml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. AWSTemplateFormatVersion: "2010-09-09"
  2. Description: Amazon S3 Find and Forget DDB Tables
  3. Metadata:
  4. cfn-lint:
  5. config:
  6. ignore_checks:
  7. - W1001
  8. Parameters:
  9. EnableBackups:
  10. Type: String
  11. RetainTables:
  12. Type: String
  13. Conditions:
  14. ShouldNotRetainTables: !Equals [!Ref RetainTables, "false"]
  15. ShouldRetainTables: !Equals [!Ref RetainTables, "true"]
  16. Resources:
  17. # DeletionPolicy and UpdateReplacePolicy need a String
  18. # https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/162
  19. DeletionQueueTableNotRetain:
  20. Type: AWS::DynamoDB::Table
  21. Condition: ShouldNotRetainTables
  22. DeletionPolicy: Delete
  23. UpdateReplacePolicy: Delete
  24. Properties:
  25. StreamSpecification:
  26. StreamViewType: NEW_IMAGE
  27. AttributeDefinitions:
  28. -
  29. AttributeName: DeletionQueueItemId
  30. AttributeType: S
  31. KeySchema:
  32. -
  33. AttributeName: DeletionQueueItemId
  34. KeyType: HASH
  35. BillingMode: PAY_PER_REQUEST
  36. PointInTimeRecoverySpecification:
  37. PointInTimeRecoveryEnabled: !Ref EnableBackups
  38. SSESpecification:
  39. KMSMasterKeyId: alias/aws/dynamodb
  40. SSEEnabled: true
  41. SSEType: KMS
  42. DeletionQueueTableRetain:
  43. Type: AWS::DynamoDB::Table
  44. Condition: ShouldRetainTables
  45. DeletionPolicy: Retain
  46. UpdateReplacePolicy: Retain
  47. Properties:
  48. StreamSpecification:
  49. StreamViewType: NEW_IMAGE
  50. AttributeDefinitions:
  51. -
  52. AttributeName: DeletionQueueItemId
  53. AttributeType: S
  54. KeySchema:
  55. -
  56. AttributeName: DeletionQueueItemId
  57. KeyType: HASH
  58. BillingMode: PAY_PER_REQUEST
  59. PointInTimeRecoverySpecification:
  60. PointInTimeRecoveryEnabled: !Ref EnableBackups
  61. SSESpecification:
  62. KMSMasterKeyId: alias/aws/dynamodb
  63. SSEEnabled: true
  64. SSEType: KMS
  65. DataMapperTableNotRetain:
  66. Type: AWS::DynamoDB::Table
  67. Condition: ShouldNotRetainTables
  68. DeletionPolicy: Delete
  69. UpdateReplacePolicy: Delete
  70. Properties:
  71. AttributeDefinitions:
  72. -
  73. AttributeName: DataMapperId
  74. AttributeType: S
  75. KeySchema:
  76. -
  77. AttributeName: DataMapperId
  78. KeyType: HASH
  79. BillingMode: PAY_PER_REQUEST
  80. PointInTimeRecoverySpecification:
  81. PointInTimeRecoveryEnabled: !Ref EnableBackups
  82. SSESpecification:
  83. KMSMasterKeyId: alias/aws/dynamodb
  84. SSEEnabled: true
  85. SSEType: KMS
  86. DataMapperTableRetain:
  87. Type: AWS::DynamoDB::Table
  88. Condition: ShouldRetainTables
  89. DeletionPolicy: Retain
  90. UpdateReplacePolicy: Retain
  91. Properties:
  92. AttributeDefinitions:
  93. -
  94. AttributeName: DataMapperId
  95. AttributeType: S
  96. KeySchema:
  97. -
  98. AttributeName: DataMapperId
  99. KeyType: HASH
  100. BillingMode: PAY_PER_REQUEST
  101. PointInTimeRecoverySpecification:
  102. PointInTimeRecoveryEnabled: !Ref EnableBackups
  103. SSESpecification:
  104. KMSMasterKeyId: alias/aws/dynamodb
  105. SSEEnabled: true
  106. SSEType: KMS
  107. JobTableNotRetain:
  108. Type: AWS::DynamoDB::Table
  109. Condition: ShouldNotRetainTables
  110. DeletionPolicy: Delete
  111. UpdateReplacePolicy: Delete
  112. Properties:
  113. TimeToLiveSpecification:
  114. AttributeName: Expires
  115. Enabled: true
  116. StreamSpecification:
  117. StreamViewType: NEW_AND_OLD_IMAGES
  118. AttributeDefinitions:
  119. -
  120. AttributeName: Id
  121. AttributeType: S
  122. -
  123. AttributeName: Sk
  124. AttributeType: S
  125. -
  126. AttributeName: GSIBucket
  127. AttributeType: S
  128. -
  129. AttributeName: CreatedAt
  130. AttributeType: N
  131. KeySchema:
  132. -
  133. AttributeName: Id
  134. KeyType: HASH
  135. -
  136. AttributeName: Sk
  137. KeyType: RANGE
  138. BillingMode: PAY_PER_REQUEST
  139. GlobalSecondaryIndexes:
  140. -
  141. IndexName: Date-GSI
  142. KeySchema:
  143. -
  144. AttributeName: GSIBucket
  145. KeyType: HASH
  146. -
  147. AttributeName: CreatedAt
  148. KeyType: RANGE
  149. Projection:
  150. ProjectionType: ALL
  151. PointInTimeRecoverySpecification:
  152. PointInTimeRecoveryEnabled: !Ref EnableBackups
  153. SSESpecification:
  154. KMSMasterKeyId: alias/aws/dynamodb
  155. SSEEnabled: true
  156. SSEType: KMS
  157. JobTableRetain:
  158. Type: AWS::DynamoDB::Table
  159. Condition: ShouldRetainTables
  160. DeletionPolicy: Retain
  161. UpdateReplacePolicy: Retain
  162. Properties:
  163. TimeToLiveSpecification:
  164. AttributeName: Expires
  165. Enabled: true
  166. StreamSpecification:
  167. StreamViewType: NEW_AND_OLD_IMAGES
  168. AttributeDefinitions:
  169. -
  170. AttributeName: Id
  171. AttributeType: S
  172. -
  173. AttributeName: Sk
  174. AttributeType: S
  175. -
  176. AttributeName: GSIBucket
  177. AttributeType: S
  178. -
  179. AttributeName: CreatedAt
  180. AttributeType: N
  181. KeySchema:
  182. -
  183. AttributeName: Id
  184. KeyType: HASH
  185. -
  186. AttributeName: Sk
  187. KeyType: RANGE
  188. BillingMode: PAY_PER_REQUEST
  189. GlobalSecondaryIndexes:
  190. -
  191. IndexName: Date-GSI
  192. KeySchema:
  193. -
  194. AttributeName: GSIBucket
  195. KeyType: HASH
  196. -
  197. AttributeName: CreatedAt
  198. KeyType: RANGE
  199. Projection:
  200. ProjectionType: ALL
  201. PointInTimeRecoverySpecification:
  202. PointInTimeRecoveryEnabled: !Ref EnableBackups
  203. SSESpecification:
  204. KMSMasterKeyId: alias/aws/dynamodb
  205. SSEEnabled: true
  206. SSEType: KMS
  207. Outputs:
  208. DeletionQueueTable:
  209. Value: !If
  210. - ShouldRetainTables
  211. - !Ref DeletionQueueTableRetain
  212. - !Ref DeletionQueueTableNotRetain
  213. DeletionQueueTableStreamArn:
  214. Value: !If
  215. - ShouldRetainTables
  216. - !GetAtt DeletionQueueTableRetain.StreamArn
  217. - !GetAtt DeletionQueueTableNotRetain.StreamArn
  218. DataMapperTable:
  219. Value: !If
  220. - ShouldRetainTables
  221. - !Ref DataMapperTableRetain
  222. - !Ref DataMapperTableNotRetain
  223. JobTable:
  224. Value: !If
  225. - ShouldRetainTables
  226. - !Ref JobTableRetain
  227. - !Ref JobTableNotRetain
  228. JobTableDateGSI:
  229. Value: Date-GSI
  230. JobTableStreamArn:
  231. Value: !If
  232. - ShouldRetainTables
  233. - !GetAtt JobTableRetain.StreamArn
  234. - !GetAtt JobTableNotRetain.StreamArn