Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: switch from using GSIs to Scan operations for both the response archiver and the nagware lambda functions #726

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

craigzour
Copy link
Contributor

@craigzour craigzour commented Jul 15, 2024

Summary | Résumé

  • Removed Archive and Nagware GSIs
  • Implemented DynamoDB Scan operations for both the response archiver and the nagware lambda functions
  • Increased timeout for both the Response Archiver and Nagware lambda functions from 5 minutes to 15 minutes just in case scan operations takes more time to complete. From my tests and the amount of elements we have in the Vault it should still be fairly quick.
  • Converted some DynamoDB operations to use lib-dynamodb instead of client-dynamodb.

The goal is to reduce the number of GSIs that need to be updated when a form response if downloaded and/or confirmed. This should reduce our consumption of Write capacity unit on the Vault table, thus preventing our system from being throttled by DynamoDB.

@craigzour craigzour self-assigned this Jul 15, 2024
@craigzour craigzour force-pushed the chore/switch-from-using-gsi-to-scan-operations branch from 881fb80 to 3645f19 Compare July 15, 2024 19:30
@craigzour craigzour marked this pull request as ready for review July 15, 2024 19:31
@craigzour craigzour force-pushed the chore/switch-from-using-gsi-to-scan-operations branch from 3645f19 to 95564f8 Compare July 15, 2024 19:33
@craigzour craigzour force-pushed the chore/switch-from-using-gsi-to-scan-operations branch from 95564f8 to 424181f Compare July 16, 2024 12:47
Copy link

⚠ Terrform update available

Terraform: 1.9.2 (using 1.6.6)
Terragrunt: 0.62.1 (using 0.54.8)

Copy link

Staging: dynamodb

✅   Terraform Init: success
✅   Terraform Validate: success
✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

Plan: 0 to add, 1 to change, 0 to destroy
Show summary
CHANGE NAME
update aws_dynamodb_table.vault
Show plan
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_dynamodb_table.vault will be updated in-place
  ~ resource "aws_dynamodb_table" "vault" {
        id                          = "Vault"
        name                        = "Vault"
        tags                        = {}
        # (13 unchanged attributes hidden)

      - attribute {
          - name = "CreatedAt" -> null
          - type = "N" -> null
        }
      - attribute {
          - name = "RemovalDate" -> null
          - type = "N" -> null
        }

      - global_secondary_index {
          - hash_key           = "FormID" -> null
          - name               = "Status" -> null
          - non_key_attributes = [] -> null
          - projection_type    = "ALL" -> null
          - range_key          = "Status" -> null
          - read_capacity      = 0 -> null
          - write_capacity     = 0 -> null
        }
      - global_secondary_index {
          - hash_key           = "Status" -> null
          - name               = "Archive" -> null
          - non_key_attributes = [] -> null
          - projection_type    = "ALL" -> null
          - range_key          = "RemovalDate" -> null
          - read_capacity      = 0 -> null
          - write_capacity     = 0 -> null
        }
      - global_secondary_index {
          - hash_key           = "Status" -> null
          - name               = "Nagware" -> null
          - non_key_attributes = [
              - "FormID",
            ] -> null
          - projection_type    = "INCLUDE" -> null
          - range_key          = "CreatedAt" -> null
          - read_capacity      = 0 -> null
          - write_capacity     = 0 -> null
        }
      + global_secondary_index {
          + hash_key           = "FormID"
          + name               = "Status"
          + non_key_attributes = []
          + projection_type    = "ALL"
          + range_key          = "Status"
        }

        # (6 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"
Show Conftest results
WARN - plan.json - main - Missing Common Tags: ["aws_dynamodb_table.audit_logs"]
WARN - plan.json - main - Missing Common Tags: ["aws_dynamodb_table.reliability_queue"]
WARN - plan.json - main - Missing Common Tags: ["aws_dynamodb_table.vault"]

22 tests, 19 passed, 3 warnings, 0 failures, 0 exceptions

Copy link

Staging: lambdas

✅   Terraform Init: success
✅   Terraform Validate: success
✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

Plan: 0 to add, 2 to change, 0 to destroy
Show summary
CHANGE NAME
update aws_lambda_function.nagware
aws_lambda_function.response_archiver
Show plan
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_lambda_function.nagware will be updated in-place
  ~ resource "aws_lambda_function" "nagware" {
        id                             = "nagware"
        tags                           = {}
      ~ timeout                        = 300 -> 900
        # (19 unchanged attributes hidden)

        # (4 unchanged blocks hidden)
    }

  # aws_lambda_function.response_archiver will be updated in-place
  ~ resource "aws_lambda_function" "response_archiver" {
        id                             = "response-archiver"
        tags                           = {}
      ~ timeout                        = 300 -> 900
        # (19 unchanged attributes hidden)

        # (4 unchanged blocks hidden)
    }

Plan: 0 to add, 2 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"
Show Conftest results
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_event_rule.audit_logs_archiver_lambda_trigger"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_event_rule.form_archiver_lambda_trigger"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_event_rule.nagware_lambda_trigger"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_event_rule.reliability_dlq_lambda_trigger"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_event_rule.response_archiver_lambda_trigger"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.archive_form_templates"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.audit_logs"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.audit_logs_archiver"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.dead_letter_queue_consumer"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.nagware"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.reliability"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.response_archiver"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.submission"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.vault_integrity"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.lambda_dynamodb"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.lambda_kms"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.lambda_logging"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.lambda_rds"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.lambda_s3"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.lambda_secrets"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.lambda_sns"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.lambda_sqs"]
WARN -...

Copy link
Contributor

@bryan-robitaille bryan-robitaille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Work!

@craigzour craigzour merged commit c09caba into develop Jul 16, 2024
13 checks passed
@craigzour craigzour deleted the chore/switch-from-using-gsi-to-scan-operations branch July 16, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants