Antipattern: AWS - Expensive DynamoDB
AWS DynamoDB tables often use features that carry cost but are not required, especially for infrequently accessed tables.
Context
DynamoDB tables might use provisioned billing mode, have high (>1) read/write capacity, or use global secondary indices. These features carry additional cost and are not always required, especially for infrequently accessed tables.
Solution
Switching to pay-per-request billing mode, reducing provisioned read/write capacity, and removing global secondary indices are ways to cost-optimize DynamoDB tables.
Example
Set billing mode to pay-per-request:
resource "aws_dynamodb_table" "example_table" {
name = "HighScores"
billing_mode = "PAY_PER_REQUEST"
attribute {
name = "UserID"
type = "S"
}
attribute {
name = "Score"
type = "N"
}
}
References
- Resource: aws_dynamodb_table (Terraform)
- DynamoDB throughput capacity - Amazon DynamoDB
- Using Global Secondary Indexes in DynamoDB - Amazon DynamoDB
- Provisioned capacity mode - Amazon DynamoDB
Occurrences
Terraform
- https://github.com/deptno/terraform-aws-modules/commit/49f447bdbb3cf23499e8194e78f852ea1e256d3a
- https://github.com/ONSdigital/eq-terraform-dynamodb/commit/40eb651a50d0dfd5cf047ef62c8a6259c1c66e02
- https://github.com/olliefr/aws-terraform-cloud1/commit/bf753832a519b0649f8d58d93aa643afe3f94fc7
- https://github.com/garylb2/terraform-example-patterns/commit/6de6d83d930bd9459e1cf8c311fa7b45c3f90987
- https://github.com/Arkoprabho/TerraformTutorial/commit/ba317d7e402f014589e230fad8c7384016211ba2
- https://github.com/jkstenzel95/jks.gameservers/commit/411ab992ba07e698cb08b56eb4cfc9d6e001d43f
- https://github.com/techservicesillinois/aws-enterprise-vpc/commit/0d21bea79e1936e2bdaee58bd6e328dd08e59b30
- https://github.com/austin1237/gifbot/commit/c11dabf1ea02c0e044c62448986bb3f9abdf3967
- https://github.com/servers-tf/infrastructure/commit/cc9e50a3864511f9fb9f871293e6a6e7e2719d2c
- https://github.com/jsoconno/aws-terraform-remote-state-infrastructure/commit/fed8be2748bc2286a6f9888d282d66763ba612ed
- https://github.com/ONSdigital/eq-terraform/commit/6eaf697bf9f111214a6d74ee3094e5784a57d1bb
- https://github.com/nikkiwritescode/flask-app-terraform-deployment/commit/af47bb6201f1dcc8264e60da429e4ff8d126e56c
- https://github.com/kperson/terraform-modules/commit/53bd2d84776f9ed7ae287fc59ed42f87bd7bbc4b
- https://github.com/kody-abe/terraform/commit/169c7768b0b1584945362c035a2b227d2f579466
- https://github.com/jenkins-x/terraform-aws-eks-jx/commit/cce6b14692fccd30c027851607a9526151d4c3d2
- https://github.com/telia-oss/terraform-aws-terraform-init/commit/e8c7b2eb22d08ddd1a1bb375cb6efa4165c9098f
- https://github.com/trajano/terraform-s3-backend/commit/f4b61c7bedae856439f01499de1ec9050b4c40fc
- https://github.com/poldi2015/chat-app/commit/cb45bf17da799afaa789206e3fcd39d9403e0567
- https://github.com/tesera/terraform-modules/commit/3cd4d7b55ac2003153fd0670151ab395ae182431
- https://github.com/MichaelDeCorte/TerraForm/commit/3799ee8b9677d02254eb6d6f50f3732df4c8374e
- https://github.com/TalkingFox/SignalWs/commit/935d9d683608b4d8a97ef6ccc2c8ab7c14eec0d0
- https://github.com/codequest-eu/terraform-modules/commit/ffe23d4c2cd78035bef0dfb261701e7ed8dd588d
- https://github.com/dgorbov/terraform-s3-backend-setup/commit/81f82740760a357a86b3a77f9ed400624edcb218
- https://github.com/sbogacz/terraform-aws-state-backend/commit/174486319f3b956807d56e5433880f9978884f93
- https://github.com/giuseppeborgese/terraform-locking-s3-state/commit/6b4e59e8b844417dc5c247bdef1b0adb8e2e7028
- https://github.com/Accurate0/infrastructure/commit/eef88fd3e61cf4b5e04682824e76df5348b60de5
- https://github.com/ministryofjustice/cloud-platform-environments/commit/0c1b4028575aeaabf7543c7357c4e26d610677c3
AWS CloudFormation
- https://github.com/turnerlabs/antiope/commit/40a968167182170aa0827ae182bbf72e5e0fd84e
- https://github.com/guardian/mobile-purchases/commit/1c500f5f94de681b5ead3a6ceba208d3efcc790e
- https://github.com/govuk-one-login/txma-infra/commit/dc9567e61048e1bd6993e546c05bcf1a3ce3c3bb
- https://github.com/vladikk/elastic-event-store/commit/4db976b88850eb08a5a36e456312fba05bad42b6
- https://github.com/ruzickap/k8s-tf-eks-gitops/commit/639d0aecc85e4c8da9d538ccb3f28b8f3a9f2d9b
- https://github.com/guardian/mobile-save-for-later/commit/5e8c85b56c8dbe36bc6bf0522dcf947a98ebfc17
- https://github.com/pagopa/pn-radd-fsu/commit/9dd31982fe3540a4ce4b97073f1fd0b97ccff425
- https://github.com/ahamlinman/randomizer/commit/431334e19f28f2da629749345d142c23a2f54888
- https://github.com/aws-cloudformation/cfn-lint/commit/201b12733558c4d7f1ee84bda84fe1a756537265
- https://github.com/Checkmarx/kics/commit/2cba29eeecb8afe156623bc7a6a9712d3fc90433
- https://github.com/turnerlabs/antiope/commit/d2b306008cc3f18af8be8ba1e52ec5ec0a82128b
- https://github.com/casual-simulation/casualos/commit/5140af5e7ab7fae1665352f27dbda887df09f0a2
- https://github.com/koekalenteri/koekalenteri/commit/232becdb8b348bb397ecdf3aeed57da85fcdf710
- https://github.com/stelligent/cfn_nag/commit/f2f5b5a7ef68602ad3d358a77ae76fa22f7c15df
- https://github.com/guardian/mobile-save-for-later/commit/b0afd91084a5ede68e2a53f2a7624f6cc9c27c64
- https://github.com/pagopa/pn-ec/commit/6d201e8153c83c8fe177914ea6ddf097c79d218a
- https://github.com/burke1791/march-madness-calcutta-api/commit/7db4e6e7b67039dc44cae29d3cee1e354a6a6875
- https://github.com/aws-samples/accelerated-data-lake/commit/18bff2bf18a685c840db98d95bd7b7cec03e0e4b
- https://github.com/gnelabs/EpithyRoboTrader/commit/cd6ff50175c1cebc7f448316db46c76e1f357a57
- https://github.com/shinesolutions/aem-aws-stack-builder/commit/7781d14d29b7e19a8b1e2dd46f4904a3041019f4
- https://github.com/guardian/mobile-save-for-later/commit/4ab126e31b1fa32bc3dbb3750bf6dee13de028ef
- https://github.com/caseconsulting/expense-app-api/commit/b2cc61e36477d2b16f0585edba815dbb8d5481c5
- https://github.com/AlisProject/serverless-application/commit/8e8617e3d1054a467945b126496ab05051f656e2
- https://github.com/DEFRA/rod-licensing/commit/5b84cfd0ee4c3d0450be8bf0760507e1655d7992
- https://github.com/NHSDigital/eps-prescription-status-update-api/commit/fe59672a63be823be78f01583ecc8fbce276d6e1
- https://github.com/aws-samples/serverless-rss-filtered-feed-gen/commit/98257ddc10439d60dd87228c0d0c0a5f6bd181ff
- https://github.com/guardian/mobile-n10n/commit/9292c2b30a75a14bb1f662e5bba20468cb3afab3
- https://github.com/gsx95/georgguessr/commit/efbf4b21260a2fea57be2edeea93db0d3c655be1
- https://github.com/biometrixtech/PreProcessing/commit/a37aacc476440312c9da9b20a769600ed082e2d3
- https://github.com/UBC-CIC/EC2Ensemble/commit/ac41affcd965cfe84b69fa05f5072ac17dc6e77c
- https://github.com/pagopa/pn-mandate/commit/f8b0624eff443ac5684d76dfe1059f1a99349128
- https://github.com/guardian/mobile-save-for-later/commit/0607c55b14336854960d81f9af27936b60fe747d
- https://github.com/lambci/lambci/commit/b439c25f32f82f7e318ac8acca6b1ab4796c3397
- https://github.com/viralemergence/pharos-api/commit/6ca33b173c2e9d159a65cdfd740c232e30732ee1
- https://github.com/biometrixtech/infrastructure/commit/fab4c34416dd4fec75df954c171f34d026435bb8
- https://github.com/caseconsulting/expense-app-api/commit/e585d93e5ce516cf2dcb9b87620cd6fa7b81b68e
- https://github.com/govuk-one-login/onboarding-self-service-experience/commit/9678897bfb3ce80012fa9567b1b9a3853e565539
- https://github.com/biometrixtech/Users/commit/14652ad70bf20207cb13b340aedcf66f5012dda9
- https://github.com/ASFHyP3/hyp3/commit/aa801f4d73de736cceb0dbdd2f1646f354ca7b05
- https://github.com/em-shea/vocab/commit/83904598b0023c83d5dff3cca3f242034b7b119a
- https://github.com/troyready/onica-create-2019-serverless/commit/5d80f28767a7b42a7cad730c672272a197d1e364
- https://github.com/aws-samples/aws-serverless-workshop-innovator-island/commit/4b992a5c2701dd79274cab30031f4acd5e130107