DYNAMODB_GET - Buscar Item por Chave
O que é este Node?
O DYNAMODB_GET é o node responsável por recuperar um item específico de uma tabela DynamoDB usando sua chave primária (Partition Key e Sort Key, se aplicável).
Por que este Node existe?
Buscar dados rapidamente é essencial em qualquer sistema. O DYNAMODB_GET existe para:
- Performance: Busca extremamente rápida (milissegundos) usando a chave primária
- Consistência: Permite leitura consistente ou eventualmente consistente
- Custo-efetivo: GetItem é a operação de leitura mais barata do DynamoDB
- Simplicidade: Retorna exatamente um item por busca (ou nenhum)
Como funciona internamente?
Quando o DYNAMODB_GET é executado, o sistema:
- Autentica: Valida as credenciais AWS (Access Key ID e Secret Access Key)
- Conecta: Estabelece conexão com o DynamoDB na região especificada
- Monta Chave: Cria objeto com Partition Key (e Sort Key, se aplicável)
- Busca: Executa GetItem na partição correta (operação O(1) - constante)
- Se encontrado: Retorna o item completo com todos os atributos
- Se não encontrado: Retorna sucesso com item = undefined
- Retorna: Resultado da busca ao flow
Código interno (aws-executors.service.ts:303-311):
case 'getItem':
const getResult = await dynamodb.get({
TableName: data.tableName,
Key: data.key,
}).promise();
return {
success: true,
item: getResult.Item,
};
Quando você DEVE usar este Node?
Use DYNAMODB_GET sempre que precisar de buscar dados específicos por chave:
Casos de uso
- Buscar perfil de usuário: "Recuperar dados completos do usuário pelo email"
- Verificar existência: "Checar se produto existe antes de processar pedido"
- Carregar configurações: "Obter configurações da conta pelo ID"
- Validar sessão: "Buscar token de sessão para autenticação"
Quando NÃO usar DYNAMODB_GET
- Buscar múltiplos itens: Use DYNAMODB_QUERY ou DYNAMODB_SCAN ao invés
- Buscar por atributo que não é chave: Use DYNAMODB_SCAN ou GSI (Global Secondary Index)
- Buscar com filtros complexos: Use DYNAMODB_QUERY com FilterExpression
- Buscar todos os itens: Use DYNAMODB_SCAN
Parâmetros Detalhados
accessKeyId (string, obrigatório)
O que é: Chave de acesso da AWS para autenticação. Obtida no Console IAM da AWS.
Padrão: Nenhum (sempre obrigatório)
Flow completo para testar:
{
"name": "Teste DynamoDB Get - Access Key ID",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "input_1",
"type": "input",
"position": { "x": 300, "y": 100 },
"data": {
"label": "User ID",
"parameters": {
"message": "Digite o ID do usuário para buscar:",
"variableName": "user_id"
}
}
},
{
"id": "dynamodb_1",
"type": "dynamodb_get",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Buscar Usuário",
"parameters": {
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"region": "us-east-1",
"operation": "getItem",
"tableName": "Usuarios",
"key": {
"userId": "{{user_id}}"
}
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Mostrar Dados",
"parameters": {
"message": "Usuário encontrado:\n{{dynamodb_1.item}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "input_1" },
{ "source": "input_1", "target": "dynamodb_1" },
{ "source": "dynamodb_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: Digite um ID de usuário. Se as credenciais forem inválidas, verá erro de autenticação.
secretAccessKey (string, obrigatório)
O que é: Chave secreta da AWS, usada junto com o Access Key ID para autenticação.
Padrão: Nenhum (sempre obrigatório)
Flow completo para testar:
{
"name": "Teste DynamoDB Get - Secret Key",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "input_1",
"type": "input",
"position": { "x": 300, "y": 100 },
"data": {
"label": "Email",
"parameters": {
"message": "Digite seu email:",
"variableName": "email"
}
}
},
{
"id": "dynamodb_1",
"type": "dynamodb_get",
"position": { "x": 500, "y": 100 },
"data": {
"label": "Buscar por Email",
"parameters": {
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"region": "sa-east-1",
"operation": "getItem",
"tableName": "Usuarios",
"key": {
"email": "{{email}}"
}
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Resultado",
"parameters": {
"message": "Dados encontrados para {{email}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 900, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "input_1" },
{ "source": "input_1", "target": "dynamodb_1" },
{ "source": "dynamodb_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: Digite um email cadastrado. Se encontrado, mostra os dados.
region (string, obrigatório)
O que é: Região AWS onde sua tabela DynamoDB está hospedada.
Padrão: Nenhum (sempre obrigatório)
Flow completo para testar:
{
"name": "Teste DynamoDB Get - Region",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 150 },
"data": { "label": "Início" }
},
{
"id": "input_1",
"type": "input",
"position": { "x": 250, "y": 150 },
"data": {
"label": "Product ID",
"parameters": {
"message": "Digite o código do produto:",
"variableName": "product_id"
}
}
},
{
"id": "switch_1",
"type": "switch",
"position": { "x": 400, "y": 150 },
"data": {
"label": "Escolher Região",
"parameters": {
"message": "Qual região buscar?\n1️⃣ US (Norte)\n2️⃣ Brasil (São Paulo)",
"cases": [
{ "value": "1", "label": "US" },
{ "value": "2", "label": "BR" }
]
}
}
},
{
"id": "dynamodb_1",
"type": "dynamodb_get",
"position": { "x": 550, "y": 100 },
"data": {
"label": "Buscar US",
"parameters": {
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"region": "us-east-1",
"operation": "getItem",
"tableName": "Produtos",
"key": { "productId": "{{product_id}}" }
}
}
},
{
"id": "dynamodb_2",
"type": "dynamodb_get",
"position": { "x": 550, "y": 200 },
"data": {
"label": "Buscar BR",
"parameters": {
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"region": "sa-east-1",
"operation": "getItem",
"tableName": "Produtos",
"key": { "productId": "{{product_id}}" }
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 150 },
"data": {
"label": "Mostrar",
"parameters": {
"message": "Produto encontrado na região selecionada"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 850, "y": 150 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "input_1" },
{ "source": "input_1", "target": "switch_1" },
{ "source": "switch_1", "target": "dynamodb_1", "label": "1" },
{ "source": "switch_1", "target": "dynamodb_2", "label": "2" },
{ "source": "dynamodb_1", "target": "message_1" },
{ "source": "dynamodb_2", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: Escolha uma região. A tabela deve existir naquela região específica.
tableName (string, obrigatório)
O que é: Nome da tabela DynamoDB de onde buscar o item.
Padrão: Nenhum (sempre obrigatório)
Flow completo para testar:
{
"name": "Teste DynamoDB Get - Table Name",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "input_1",
"type": "input",
"position": { "x": 250, "y": 100 },
"data": {
"label": "Nome da Tabela",
"parameters": {
"message": "Digite o nome da tabela:",
"variableName": "table_name"
}
}
},
{
"id": "input_2",
"type": "input",
"position": { "x": 400, "y": 100 },
"data": {
"label": "ID",
"parameters": {
"message": "Digite o ID do item:",
"variableName": "item_id"
}
}
},
{
"id": "dynamodb_1",
"type": "dynamodb_get",
"position": { "x": 550, "y": 100 },
"data": {
"label": "Buscar Item",
"parameters": {
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"region": "us-east-1",
"operation": "getItem",
"tableName": "{{table_name}}",
"key": {
"id": "{{item_id}}"
}
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 100 },
"data": {
"label": "Resultado",
"parameters": {
"message": "Busca concluída na tabela: {{table_name}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 850, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "input_1" },
{ "source": "input_1", "target": "input_2" },
{ "source": "input_2", "target": "dynamodb_1" },
{ "source": "dynamodb_1", "target": "message_1" },
{ "source": "message_1", "target": "end_1" }
]
}
Teste: Digite nome de tabela existente e ID válido. Se a tabela não existir, erro "ResourceNotFoundException".
key (object, obrigatório)
O que é: Objeto contendo a chave primária do item a buscar. DEVE incluir Partition Key e Sort Key (se a tabela tiver).
Padrão: Nenhum (sempre obrigatório)
Flow completo para testar:
{
"name": "Teste DynamoDB Get - Key",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 100 },
"data": { "label": "Início" }
},
{
"id": "email_1",
"type": "email",
"position": { "x": 250, "y": 100 },
"data": {
"label": "Email",
"parameters": {
"message": "Digite seu email para buscar perfil:",
"variableName": "user_email"
}
}
},
{
"id": "dynamodb_1",
"type": "dynamodb_get",
"position": { "x": 400, "y": 100 },
"data": {
"label": "Buscar Perfil",
"parameters": {
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"region": "us-east-1",
"operation": "getItem",
"tableName": "Usuarios",
"key": {
"userId": "{{user_email}}"
}
}
}
},
{
"id": "condition_1",
"type": "condition",
"position": { "x": 550, "y": 100 },
"data": {
"label": "Item Existe?",
"parameters": {
"variable": "{{dynamodb_1.item}}",
"operator": "exists"
}
}
},
{
"id": "message_1",
"type": "message",
"position": { "x": 700, "y": 50 },
"data": {
"label": "Encontrado",
"parameters": {
"message": "✅ Perfil encontrado!\n\n👤 Nome: {{dynamodb_1.item.nome}}\n📧 Email: {{dynamodb_1.item.email}}\n📱 Telefone: {{dynamodb_1.item.telefone}}"
}
}
},
{
"id": "message_2",
"type": "message",
"position": { "x": 700, "y": 150 },
"data": {
"label": "Não Encontrado",
"parameters": {
"message": "❌ Usuário não encontrado para email: {{user_email}}"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 850, "y": 100 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "email_1" },
{ "source": "email_1", "target": "dynamodb_1" },
{ "source": "dynamodb_1", "target": "condition_1" },
{ "source": "condition_1", "target": "message_1", "label": "true" },
{ "source": "condition_1", "target": "message_2", "label": "false" },
{ "source": "message_1", "target": "end_1" },
{ "source": "message_2", "target": "end_1" }
]
}
Teste: Digite um email cadastrado. Se encontrado, mostra dados; se não, informa ausência.
Parâmetros
| Campo | Tipo | Obrigatório | Descrição |
|---|---|---|---|
| accessKeyId | string | Sim | Chave de acesso AWS (IAM) |
| secretAccessKey | string | Sim | Chave secreta AWS |
| region | string | Sim | Região AWS (ex: us-east-1, sa-east-1) |
| operation | string | Sim | Tipo de operação (sempre "getItem") |
| tableName | string | Sim | Nome da tabela DynamoDB |
| key | object | Sim | Chave primária (Partition Key + Sort Key se houver) |
Exemplo 1: Login - Buscar Usuário por Email
Objetivo: Demonstrar busca de perfil de usuário para autenticação.
JSON para Importar
{
"name": "Login - Buscar Usuário por Email",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 200 },
"data": { "label": "Início" }
},
{
"id": "message_1",
"type": "message",
"position": { "x": 250, "y": 200 },
"data": {
"label": "Boas-vindas",
"parameters": {
"message": "🔐 Sistema de Login\n\nVamos buscar seu perfil."
}
}
},
{
"id": "email_1",
"type": "email",
"position": { "x": 400, "y": 200 },
"data": {
"label": "Email",
"parameters": {
"message": "Digite seu email:",
"variableName": "login_email"
}
}
},
{
"id": "dynamodb_1",
"type": "dynamodb_get",
"position": { "x": 550, "y": 200 },
"data": {
"label": "Buscar Usuário",
"parameters": {
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"region": "sa-east-1",
"operation": "getItem",
"tableName": "Usuarios",
"key": {
"userId": "{{login_email}}"
}
}
}
},
{
"id": "condition_1",
"type": "condition",
"position": { "x": 700, "y": 200 },
"data": {
"label": "Usuário Existe?",
"parameters": {
"variable": "{{dynamodb_1.item}}",
"operator": "exists"
}
}
},
{
"id": "message_2",
"type": "message",
"position": { "x": 850, "y": 150 },
"data": {
"label": "Login OK",
"parameters": {
"message": "✅ Login bem-sucedido!\n\n🎉 Bem-vindo, {{dynamodb_1.item.nome}}!\n\n📊 Seus dados:\n📧 Email: {{dynamodb_1.item.email}}\n📱 Telefone: {{dynamodb_1.item.telefone}}\n📅 Membro desde: {{dynamodb_1.item.dataCadastro}}\n🎯 Status: {{dynamodb_1.item.status}}"
}
}
},
{
"id": "message_3",
"type": "message",
"position": { "x": 850, "y": 250 },
"data": {
"label": "Não Encontrado",
"parameters": {
"message": "❌ Email não cadastrado!\n\n{{login_email}} não foi encontrado no sistema.\n\nDeseja se cadastrar?"
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 1000, "y": 200 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "message_1" },
{ "source": "message_1", "target": "email_1" },
{ "source": "email_1", "target": "dynamodb_1" },
{ "source": "dynamodb_1", "target": "condition_1" },
{ "source": "condition_1", "target": "message_2", "label": "true" },
{ "source": "condition_1", "target": "message_3", "label": "false" },
{ "source": "message_2", "target": "end_1" },
{ "source": "message_3", "target": "end_1" }
]
}
Saída esperada:
Sistema: 🔐 Sistema de Login
Vamos buscar seu perfil.
Sistema: Digite seu email:
Usuário: jose@example.com
Sistema: ✅ Login bem-sucedido!
🎉 Bem-vindo, José Roberto Silva!
📊 Seus dados:
📧 Email: jose@example.com
📱 Telefone: (11) 98765-4321
📅 Membro desde: 2025-01-15
🎯 Status: ativo
Exemplo 2: Verificar Estoque antes de Pedido
Objetivo: Demonstrar busca de produto para validar estoque disponível.
JSON para Importar
{
"name": "Verificar Estoque de Produto",
"nodes": [
{
"id": "start_1",
"type": "start",
"position": { "x": 100, "y": 250 },
"data": { "label": "Início" }
},
{
"id": "message_1",
"type": "message",
"position": { "x": 250, "y": 250 },
"data": {
"label": "Iniciar Compra",
"parameters": {
"message": "🛒 Bem-vindo à loja!\n\nVamos verificar disponibilidade."
}
}
},
{
"id": "input_1",
"type": "input",
"position": { "x": 400, "y": 250 },
"data": {
"label": "Código Produto",
"parameters": {
"message": "Digite o código do produto:",
"variableName": "product_code"
}
}
},
{
"id": "number_1",
"type": "number",
"position": { "x": 550, "y": 250 },
"data": {
"label": "Quantidade",
"parameters": {
"message": "Quantas unidades deseja?",
"variableName": "quantity"
}
}
},
{
"id": "dynamodb_1",
"type": "dynamodb_get",
"position": { "x": 700, "y": 250 },
"data": {
"label": "Buscar Produto",
"parameters": {
"accessKeyId": "AKIAIOSFODNN7EXAMPLE",
"secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"region": "us-east-1",
"operation": "getItem",
"tableName": "Produtos",
"key": {
"productId": "{{product_code}}"
}
}
}
},
{
"id": "condition_1",
"type": "condition",
"position": { "x": 850, "y": 250 },
"data": {
"label": "Produto Existe?",
"parameters": {
"variable": "{{dynamodb_1.item}}",
"operator": "exists"
}
}
},
{
"id": "condition_2",
"type": "condition",
"position": { "x": 1000, "y": 200 },
"data": {
"label": "Estoque Suficiente?",
"parameters": {
"variable": "{{dynamodb_1.item.estoque}}",
"operator": ">=",
"value": "{{quantity}}"
}
}
},
{
"id": "message_2",
"type": "message",
"position": { "x": 1150, "y": 150 },
"data": {
"label": "Disponível",
"parameters": {
"message": "✅ Produto disponível!\n\n📦 Produto: {{dynamodb_1.item.nome}}\n💰 Preço: R$ {{dynamodb_1.item.preco}}\n📊 Estoque: {{dynamodb_1.item.estoque}} unidades\n🛒 Quantidade: {{quantity}}\n\n💵 Total: R$ {{dynamodb_1.item.preco * quantity}}\n\nProsseguir com o pedido?"
}
}
},
{
"id": "message_3",
"type": "message",
"position": { "x": 1150, "y": 250 },
"data": {
"label": "Estoque Insuficiente",
"parameters": {
"message": "⚠️ Estoque insuficiente!\n\n📦 Produto: {{dynamodb_1.item.nome}}\n📊 Disponível: {{dynamodb_1.item.estoque}} unidades\n🛒 Solicitado: {{quantity}}\n\nDeseja ajustar a quantidade?"
}
}
},
{
"id": "message_4",
"type": "message",
"position": { "x": 1000, "y": 300 },
"data": {
"label": "Não Encontrado",
"parameters": {
"message": "❌ Produto não encontrado!\n\nCódigo {{product_code}} não existe no catálogo."
}
}
},
{
"id": "end_1",
"type": "end",
"position": { "x": 1300, "y": 200 },
"data": { "label": "Fim" }
}
],
"edges": [
{ "source": "start_1", "target": "message_1" },
{ "source": "message_1", "target": "input_1" },
{ "source": "input_1", "target": "number_1" },
{ "source": "number_1", "target": "dynamodb_1" },
{ "source": "dynamodb_1", "target": "condition_1" },
{ "source": "condition_1", "target": "condition_2", "label": "true" },
{ "source": "condition_1", "target": "message_4", "label": "false" },
{ "source": "condition_2", "target": "message_2", "label": "true" },
{ "source": "condition_2", "target": "message_3", "label": "false" },
{ "source": "message_2", "target": "end_1" },
{ "source": "message_3", "target": "end_1" },
{ "source": "message_4", "target": "end_1" }
]
}
Saída esperada:
Sistema: 🛒 Bem-vindo à loja!
Vamos verificar disponibilidade.
Sistema: Digite o código do produto:
Usuário: PROD123
Sistema: Quantas unidades deseja?
Usuário: 3
Sistema: ✅ Produto disponível!
📦 Produto: Notebook Dell
💰 Preço: R$ 2999.00
📊 Estoque: 15 unidades
🛒 Quantidade: 3
💵 Total: R$ 8997.00
Prosseguir com o pedido?
Resposta do Node
{
"success": true,
"item": {
"userId": "jose@example.com",
"nome": "José Roberto Silva",
"email": "jose@example.com",
"telefone": "(11) 98765-4321",
"dataCadastro": "2025-01-15",
"status": "ativo"
}
}
Se o item não for encontrado:
{
"success": true,
"item": undefined
}
Boas Práticas
✅ SIM:
- Sempre verifique se
itemexiste antes de acessar atributos - Use CONDITION node após GET para validar existência do item
- Cache resultados de GetItem quando o mesmo item é acessado múltiplas vezes
- Use Partition Key + Sort Key para buscas mais específicas
- Prefira GetItem a Query quando souber a chave exata (mais rápido e barato)
❌ NÃO:
- Assumir que o item sempre existe (sempre valide)
- Usar GetItem para buscar múltiplos itens (use Query ou Scan)
- Buscar por atributos que não são chaves (use Query com índice ou Scan)
- Fazer múltiplos GetItem em loop (use BatchGetItem da AWS ao invés)
- Ignorar erros de tabela não encontrada
Dicas
💡 Dica 1: GetItem retorna undefined para itens não encontrados, não um erro. Sempre valide com CONDITION após a busca.
💡 Dica 2: GetItem é consistente eventualmente por padrão. Para leitura fortemente consistente (reflete escritas recentes), adicione ConsistentRead: true no código.
💡 Dica 3: GetItem é O(1) - tempo constante, independente do tamanho da tabela. É a operação mais rápida do DynamoDB.
💡 Dica 4: Para tabelas com Partition Key + Sort Key, você DEVE fornecer ambas no parâmetro key. Sem a Sort Key, a busca falhará.
💡 Dica 5: Armazene o resultado em variável para usar em nodes seguintes: {{dynamodb_1.item.campo}}.
Próximo Node
→ DYNAMODB_PUT - Inserir ou sobrescrever item → DYNAMODB_QUERY - Buscar múltiplos itens por Partition Key → DYNAMODB_UPDATE - Atualizar campos específicos