Ir al contenido

AWS (Lambda, SQS, CloudWatch)

Las funciones Lambda se invocan mediante el SDK de AWS (aws-sdk v2).

// Invocación síncrona (InvocationType: 'RequestResponse')
await Helper.invokeAWSLambda(functionName, payload);
// Invocación asíncrona (InvocationType: 'Event')
await Helper.invokeAWSLambda(functionName, payload, true);

El nombre final de la función se construye como: {FUNCTION_NAME}-{ENV}
(excepto cuando nameIncludesEnv=true, donde el nombre se usa tal cual)

Variable de entornoPropósitoInvocación
FUNCTION_FINALITIXNOTIFICATIONS_NAMEEmail y SMS al usuarioAsíncrona
FUNCTION_FINALITIXNOTIFICATIONSPUBSUB_NAMENotificaciones WebSocket en tiempo realAsíncrona
FUNCTION_FINALITIXCONTACT_NAMECrear/actualizar contacto del ordenanteSíncrona

Ver Códigos de Error — Plantillas de Lambda.


Los mensajes SQS se usan para integración asíncrona con Odoo y para webhooks al cliente.

Cola de pólizas contables (ACC_MOVE_SQS_URL)

Sección titulada «Cola de pólizas contables (ACC_MOVE_SQS_URL)»

Envía instrucciones a Odoo para crear entradas contables.

Cargo saliente / Abono entrante:

{
"MessageAttributes": {
"method": { "DataType": "String", "StringValue": "create_post_move" },
"model": { "DataType": "String", "StringValue": "account.move" }
},
"MessageBody": {
"transaction_id": 123,
"amount": 1500.00,
"finalitix_type": "cargo",
"description": "Pago de servicios"
}
}

Creación de partner (al activar cuenta):

{
"MessageAttributes": {
"method": { "DataType": "String", "StringValue": "create_finalitix_partner" },
"model": { "DataType": "String", "StringValue": "res.partner" },
"accountId": { "DataType": "Number", "StringValue": "42" },
"finalitixUserId": { "DataType": "String", "StringValue": "user-uuid" }
},
"MessageBody": { }
}

Cola de webhooks al cliente (CUSTOMER_NOTIFICATION_SQS_URL)

Sección titulada «Cola de webhooks al cliente (CUSTOMER_NOTIFICATION_SQS_URL)»

Notifica al sistema del cliente cuando hay movimientos en sus cuentas.

{
"MessageAttributes": {
"type": { "DataType": "String", "StringValue": "abono" },
"user_id": { "DataType": "String", "StringValue": "user-uuid" },
"attempt_type": { "DataType": "String", "StringValue": "customer_webhook" }
},
"MessageBody": {
"transaction_id": 456,
"amount": 5000.00,
"account_number": "64618001000001237"
}
}

Las credenciales se obtienen al inicio de cada petición y se cachean en memoria de módulo para evitar llamadas repetidas:

// lib/helper.js — patrón de caché
let credentials = null;
credentials = await Helper.retrieveSecret(credentials, process.env.CREDENTIALS_SECRET);
// Si credentials != null, retorna el valor en caché sin llamar a AWS

Secretos usados:

VariableContenido
CREDENTIALS_SECRETUsuario, contraseña, host y nombre de BD MySQL
STP_SECRET_NAMEClaves RSA, config de STP, URLs de servicios bancarios

Trazabilidad distribuida configurada como middleware global en index.js:

// Segmento principal
const segmentName = 'Finalitix-STP-API';

Captura todas las peticiones HTTP entrantes y salientes (axios) automáticamente.


// Log group: finalitixSpeiAPILogs
// Log stream: {EC2_INSTANCE_ID}-{YYYY-MM-DD}
// Solo activo cuando ENV=prod

El middleware latencyLogger.js registra métricas por endpoint:

// Namespace: /finalitix/stp-api/performance
// Dimensiones:
// Endpoint: "/stp/v1/transaction"
// Method: "POST"
// StatusCode: "200"
// Métrica: Latency (milisegundos)

Se publica una métrica por cada petición procesada en producción.