-
Notifications
You must be signed in to change notification settings - Fork 2
feat: DynamoDB single-table Terraform module with 5 GSIs #64
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
Open
maxsonferovante
wants to merge
4
commits into
main
Choose a base branch
from
feature/single-table-dynamodb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
867f8b7
feat: add DynamoDB single-table Terraform module with 5 GSIs
maxsonferovante 7913766
docs: add DynamoDB single-table design documentation
maxsonferovante 258a80f
fix: remove GSI5 and update outputs per PR feedback
maxsonferovante 3d09189
docs: remove GSI5 from single-table documentation
maxsonferovante File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| # Single Table Design - DynamoDB | ||
| # Baseado no padrão: https://aws.amazon.com/pt/blogs/compute/creating-a-single-table-design-with-amazon-dynamodb/ | ||
| # | ||
| # Entity Patterns: | ||
| # PK: EntityType#EntityId (ex: ORDER#123, PRODUCT#1, PARTICIPANT#uuid, CERTIFICATE#123) | ||
| # SK: EntityType#EntityId (mesmo formato para acesso direto) | ||
| # | ||
| # GSIs para padrões de acesso: | ||
| # GSI1: Acesso por UUID (certificate by ID) | ||
| # GSI2: Acesso por email (orders, certificates, participants) | ||
| # GSI3: Acesso por product (products, orders, certificates) | ||
| # GSI4: Acesso por success flag (certificates) | ||
|
|
||
| resource "aws_dynamodb_table" "single_table" { | ||
| name = var.table_name | ||
| billing_mode = "PAY_PER_REQUEST" | ||
| hash_key = "PK" | ||
| range_key = "SK" | ||
|
|
||
| attribute { | ||
| name = "PK" | ||
| type = "S" | ||
| } | ||
|
|
||
| attribute { | ||
| name = "SK" | ||
| type = "S" | ||
| } | ||
|
|
||
| # Atributos base - entidades | ||
| attribute { | ||
| name = "GSI1PK" | ||
| type = "S" | ||
| } | ||
|
|
||
| attribute { | ||
| name = "GSI1SK" | ||
| type = "S" | ||
| } | ||
|
|
||
| attribute { | ||
| name = "GSI2PK" | ||
| type = "S" | ||
| } | ||
|
|
||
| attribute { | ||
| name = "GSI2SK" | ||
| type = "S" | ||
| } | ||
|
|
||
| attribute { | ||
| name = "GSI3PK" | ||
| type = "S" | ||
| } | ||
|
|
||
| attribute { | ||
| name = "GSI3SK" | ||
| type = "S" | ||
| } | ||
|
|
||
| attribute { | ||
| name = "GSI4PK" | ||
| type = "S" | ||
| } | ||
|
|
||
| attribute { | ||
| name = "GSI4SK" | ||
| type = "S" | ||
| } | ||
|
|
||
| # EntityType para identificação rápida do tipo | ||
| attribute { | ||
| name = "EntityType" | ||
| type = "S" | ||
| } | ||
|
|
||
| # GSI1: CERT# lookups (certificate find_by_id) | ||
| global_secondary_index { | ||
| name = "GSI1" | ||
| hash_key = "GSI1PK" | ||
| range_key = "GSI1SK" | ||
| projection_type = "ALL" | ||
| } | ||
|
|
||
| # GSI2: EMAIL# lookups (email lookups across entities) | ||
| global_secondary_index { | ||
| name = "GSI2" | ||
| hash_key = "GSI2PK" | ||
| range_key = "GSI2SK" | ||
| projection_type = "ALL" | ||
| } | ||
|
|
||
| # GSI3: PRODUCT# lookups (product lookups) | ||
| global_secondary_index { | ||
| name = "GSI3" | ||
| hash_key = "GSI3PK" | ||
| range_key = "GSI3SK" | ||
| projection_type = "ALL" | ||
| } | ||
|
|
||
| # GSI4: SUCCESS# lookups (certificate success flag) | ||
| global_secondary_index { | ||
| name = "GSI4" | ||
| hash_key = "GSI4PK" | ||
| range_key = "GSI4SK" | ||
| projection_type = "ALL" | ||
| } | ||
|
|
||
| server_side_encryption { | ||
| enabled = true | ||
| } | ||
|
|
||
| tags = { | ||
| Name = var.table_name | ||
| Environment = var.environment | ||
| Project = var.project_name | ||
| Design = "SingleTable" | ||
| CostCenter = "low-cost" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| output "table_name" { | ||
| value = aws_dynamodb_table.single_table.name | ||
| description = "Nome da tabela única" | ||
| } | ||
|
|
||
| output "table_arn" { | ||
| value = aws_dynamodb_table.single_table.arn | ||
| description = "ARN da tabela única" | ||
| } | ||
|
|
||
| output "table_id" { | ||
| value = aws_dynamodb_table.single_table.id | ||
| description = "ID da tabela única" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| variable "table_name" { | ||
| description = "Nome da tabela única" | ||
| type = string | ||
| } | ||
|
|
||
| variable "environment" { | ||
| description = "Ambiente de deploy" | ||
| type = string | ||
| } | ||
|
|
||
| variable "project_name" { | ||
| description = "Nome do projeto" | ||
| type = string | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O
EntityTypetá declarado comoattributemas não é chave de nada — nemhash_key/range_keyda tabela, nem de nenhum dos cinco GSIs. Isso quebra o apply no plan, antes de chamar a AWS:Testei o módulo contra o MiniStack variando só esse bloco: com ele dá o erro acima, sem ele a tabela sobe
ACTIVEcom os 5 GSIs certinhos.Pode remover — o DynamoDB é schemaless, então a aplicação continua gravando
EntityTypee usando nofilter_expressionsem precisar declarar como atributo.