Skip to content

Commit

Permalink
new: added policy ecc-aws-552-dynamodb_tables_unused
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-shcherbak committed Sep 20, 2023
1 parent 96802fe commit 11ef8ce
Show file tree
Hide file tree
Showing 24 changed files with 343 additions and 42 deletions.
1 change: 1 addition & 0 deletions iam/All-permissions.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"cloudtrail:DescribeTrails",
"cloudtrail:GetEventSelectors",
"cloudtrail:GetTrailStatus",
"cloudwatch:GetMetricStatistics",
"cloudwatch:DescribeAlarms",
"codebuild:BatchGetProjects",
"codebuild:ListProjects",
Expand Down
46 changes: 46 additions & 0 deletions policies/ecc-aws-552-dynamodb_tables_unused.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (c) 2023 EPAM Systems, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


policies:
- name: ecc-aws-552-dynamodb_tables_unused
comment: '010002062000'
description: |
Unused Amazon DynamoDB tables
resource: aws.dynamodb-table
filters:
- and:
- type: value
key: ProvisionedThroughput.ReadCapacityUnits
op: ne
value: 0
- type: value
key: TableStatus
value: ACTIVE
- type: value
key: CreationDateTime
value_type: age
value: 60
op: ge
- or:
- type: value
key: ItemCount
value: 0
- and:
- type: metrics
name: ConsumedWriteCapacityUnits
namespace: AWS/DynamoDB
statistics: Maximum
days: 60
value: 0
op: equal
- type: metrics
name: ConsumedReadCapacityUnits
namespace: AWS/DynamoDB
statistics: Maximum
days: 60
value: 0
op: equal
28 changes: 28 additions & 0 deletions terraform/ecc-aws-552-dynamodb_tables_unused/green/dynamodb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
resource "aws_dynamodb_table" "this" {
name = "552_dynamodb_table_green"
hash_key = "GreenTableHashKey"
billing_mode = "PROVISIONED"
read_capacity = 1
write_capacity = 1


attribute {
name = "GreenTableHashKey"
type = "S"
}
}

resource "aws_dynamodb_table_item" "this" {
table_name = aws_dynamodb_table.this.name
hash_key = aws_dynamodb_table.this.hash_key

item = <<ITEM
{
"GreenTableHashKey": {"S": "something"},
"one": {"N": "11111"},
"two": {"N": "22222"},
"three": {"N": "33333"},
"four": {"N": "44444"}
}
ITEM
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ provider "aws" {

default_tags {
tags = {
CustodianRule = "ecc-aws-916-waf_global_rulegroup_not_empty"
CustodianRule = "ecc-aws-552-dynamodb_tables_unused"
ComplianceStatus = "Green"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
{
"Effect": "Allow",
"Action": [
"waf:ListActivatedRulesInRuleGroup",
"waf:ListRuleGroups"
"dynamodb:ListTables",
"dynamodb:DescribeTable",
"tag:GetResources",
"cloudwatch:GetMetricStatistics"
],
"Resource": "*"
}
Expand Down
13 changes: 13 additions & 0 deletions terraform/ecc-aws-552-dynamodb_tables_unused/red/dynamodb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "aws_dynamodb_table" "this" {
name = "552_dynamodb_table_red"
hash_key = "GreenTableHashKey"
billing_mode = "PROVISIONED"
read_capacity = 1
write_capacity = 1


attribute {
name = "GreenTableHashKey"
type = "S"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ provider "aws" {

default_tags {
tags = {
CustodianRule = "ecc-aws-916-waf_global_rulegroup_not_empty"
CustodianRule = "ecc-aws-552-dynamodb_tables_unused"
ComplianceStatus = "Red"
}
}
Expand Down
34 changes: 0 additions & 34 deletions terraform/ecc-aws-916-waf_global_rulegroup_not_empty/green/waf.tf

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"status_code": 200,
"data": {
"Table": {
"AttributeDefinitions": [
{
"AttributeName": "GreenTableHashKey",
"AttributeType": "S"
}
],
"TableName": "552_dynamodb_table_green",
"KeySchema": [
{
"AttributeName": "GreenTableHashKey",
"KeyType": "HASH"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": {
"__class__": "datetime",
"year": 2023,
"month": 3,
"day": 14,
"hour": 16,
"minute": 44,
"second": 5,
"microsecond": 334000
},
"ProvisionedThroughput": {
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
},
"TableSizeBytes": 57,
"ItemCount": 1,
"TableArn": "arn:aws:dynamodb:us-east-1:123456789012:table/552_dynamodb_table_green",
"TableId": "352e6eb5-5243-487d-8b54-8d99a47658ad",
"DeletionProtectionEnabled": false
},
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"status_code": 200,
"data": {
"TableNames": [
"552_dynamodb_table_green"
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"status_code": 200,
"data": {
"Label": "ConsumedWriteCapacityUnits",
"Datapoints": [
{
"Timestamp": {
"__class__": "datetime",
"year": 2023,
"month": 6,
"day": 17,
"hour": 7,
"minute": 0,
"second": 0,
"microsecond": 0
},
"Maximum": 1.0,
"Unit": "Count"
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"status_code": 200,
"data": {
"Label": "ConsumedReadCapacityUnits",
"Datapoints": [
{
"Timestamp": {
"__class__": "datetime",
"year": 2023,
"month": 6,
"day": 17,
"hour": 7,
"minute": 0,
"second": 0,
"microsecond": 0
},
"Maximum": 0.5,
"Unit": "Count"
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"status_code": 200,
"data": {
"PaginationToken": "",
"ResourceTagMappingList": [
{
"ResourceARN": "arn:aws:dynamodb:us-east-1:123456789012:table/552_dynamodb_table_green",
"Tags": [
{
"Key": "CustodianRule",
"Value": "ecc-aws-552-dynamodb_tables_unused"
},
{
"Key": "ComplianceStatus",
"Value": "Green"
}
]
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"status_code": 200,
"data": {
"Table": {
"AttributeDefinitions": [
{
"AttributeName": "GreenTableHashKey",
"AttributeType": "S"
}
],
"TableName": "552_dynamodb_table_red",
"KeySchema": [
{
"AttributeName": "GreenTableHashKey",
"KeyType": "HASH"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": {
"__class__": "datetime",
"year": 2023,
"month": 2,
"day": 15,
"hour": 10,
"minute": 30,
"second": 45,
"microsecond": 876000
},
"ProvisionedThroughput": {
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
},
"TableSizeBytes": 0,
"ItemCount": 0,
"TableArn": "arn:aws:dynamodb:us-east-1:123456789012:table/552_dynamodb_table_red",
"TableId": "0918e866-a87a-42fd-be35-f8d7b4f29632",
"DeletionProtectionEnabled": false
},
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"status_code": 200,
"data": {
"TableNames": [
"552_dynamodb_table_red"
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"status_code": 200,
"data": {
"Label": "ConsumedWriteCapacityUnits",
"Datapoints": [
{
"Timestamp": {
"__class__": "datetime",
"year": 2023,
"month": 7,
"day": 17,
"hour": 7,
"minute": 35,
"second": 0,
"microsecond": 0
},
"Maximum": 0.0,
"Unit": "Count"
}
],
"ResponseMetadata": {}
}
}
Loading

0 comments on commit 11ef8ce

Please sign in to comment.