aloux-cloud
v1.0.0
Published
Aloux Cloud integrations: AWS S3, SES, SNS and Google BigQuery
Downloads
175
Readme
aloux-cloud
Librería Node.js de integraciones cloud: AWS S3, SES, SNS y Google BigQuery.
Instalación
npm install aloux-cloudUso básico
const { s3, ses, sns, bigQuery } = require('aloux-cloud')
await s3.upload('users/123/avatar', file)
await ses.sendCustom('[email protected]', html, 'Bienvenido')
await sns.sendMessagePhone('+521234567890', 'Tu código es: 4821')
await bigQuery.callAppendRows({ name: 'Juan' }, 'usuarios')Integración con aloux-iam
const iam = require('aloux-iam')
const cloud = require('aloux-cloud')
iam.init({
email: cloud.ses,
sms: cloud.sns,
storage: cloud.s3,
analytics: cloud.bigQuery,
})Variables de entorno
AWS
| Variable | Requerida para | Descripción |
|----------|---------------|-------------|
| AWS_REGION | S3 · SES · SNS | Región AWS |
| AWS_BUCKET | S3 | Nombre del bucket |
| AWS_EMAIL_SENDER | SES | Email remitente verificado en SES |
| FILE_MAX_SIZE_MB | S3 | Tamaño máximo de archivo en MB. Default: 5 |
Las credenciales
AWS_ACCESS_KEY_IDyAWS_SECRET_ACCESS_KEYse toman automáticamente del entorno o de un IAM Role (EC2/ECS).
Google Cloud
| Variable | Descripción |
|----------|-------------|
| PROJECT_ID | ID del proyecto en Google Cloud |
| DATASET_ID | ID del dataset en BigQuery |
También necesitas credenciales de servicio GCP. Configura
GOOGLE_APPLICATION_CREDENTIALSapuntando al archivo JSON.
S3 — Almacenamiento
Tipos de archivo permitidos: jpg · jpeg · png · gif · webp · pdf · svg
upload(pathFile, file, contentType?, acl?)
Sube un archivo al bucket. Devuelve la URL.
// pathFile — ruta dentro del bucket (sin extensión)
// file — objeto de express-fileupload (req.files.archivo)
// acl — 'private' (default) | 'public-read'
const url = await s3.upload('users/123/avatar', file, 'image/jpeg', 'public-read')
// → "https://mi-bucket.s3.amazonaws.com/users/123/avatar.jpg"delete(file)
await s3.delete('users/123/avatar.jpg')deleteMany(files)
await s3.deleteMany([
{ Key: 'products/abc/img1.jpg' },
{ Key: 'products/abc/img2.png' },
])SES — Email
send(email, url, subject)
Envía un email con un botón de acceso. Útil para bienvenida o restablecimiento de contraseña.
await ses.send(
'[email protected]',
'https://tuapp.com/set-password?token=abc123',
'Establece tu contraseña'
)sendCustom(email, html, subject)
Envía un email con HTML personalizado.
const html = `<h1>Pedido confirmado</h1><p>Tu pedido #123 está en camino.</p>`
await ses.sendCustom('[email protected]', html, 'Confirmación de pedido')SNS — SMS
sendMessagePhone(phoneNumber, message)
El número debe estar en formato E.164.
await sns.sendMessagePhone('+521234567890', 'Tu código es: 4821')| País | Formato |
|------|---------|
| México | +52XXXXXXXXXX |
| Estados Unidos | +1XXXXXXXXXX |
| España | +34XXXXXXXXX |
BigQuery
callAppendRows(rows, table)
Inserta una o varias filas en una tabla de BigQuery.
// Una fila
await bigQuery.callAppendRows(
{ name: 'Juan', email: '[email protected]', createdAt: bigQuery.factoryDateTime(Date.now()) },
'usuarios'
)
// Varias filas
await bigQuery.callAppendRows([
{ name: 'Juan', email: '[email protected]' },
{ name: 'María', email: '[email protected]' },
], 'usuarios')factoryDateTime(dateNumber)
Convierte un timestamp a formato "YYYY-MM-DDTHH:MM:SS" que espera BigQuery.
bigQuery.factoryDateTime(Date.now())
// → "2026-05-28T14:30:00"Licencia
MIT
