Skip to content

Instantly share code, notes, and snippets.

@alsantos123
Created March 30, 2021 05:59
Show Gist options
  • Select an option

  • Save alsantos123/944e63f326f496ea3ea1285c6045f53b to your computer and use it in GitHub Desktop.

Select an option

Save alsantos123/944e63f326f496ea3ea1285c6045f53b to your computer and use it in GitHub Desktop.
AWS SQS Lambda Consumer
import * as util from "util";
import { Context, Callback, SQSEvent } from "aws-lambda";
import SaldoNegocio, { ISQS_DATA } from "/opt/core/dist/SaldoNegocio";
import { TransactWriteItemList } from "aws-sdk/clients/dynamodb";
const DEBUG = true;
export const handler = async ( event: SQSEvent ): Promise<void> =>
{
try
{
const lstTrxs = [] as TransactWriteItemList;
for(let i = 0; i < event.Records.length; i++)
{
const item = event.Records[i];
const payload:ISQS_DATA = JSON.parse(item.body);
const trx = await SaldoNegocio.SQS_SALDO_RECEBEU_CRIAR_PUT_TRX(payload);
lstTrxs.push({Put: trx});
}
if(lstTrxs.length)
{
const res = await SaldoNegocio.SQS_SALDO_RECEBEU_PROCESSAR_TRXS(lstTrxs);
}
}
catch(e)
{
console.error(">>>");
console.error("sqs-saldo erro exception => ", util.inspect(e, true, 4, false));
console.error("sqs-saldo erro event => ", util.inspect(event, true, 4, false));
console.error(">>>");
throw e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment