// import constants and config const path = require("path"), rootPath = process.env.LAMBDA_TASK_ROOT ? process.env.LAMBDA_TASK_ROOT : path.dirname(require.main.filename), load = require(`${rootPath}/config/config.json`), secretConfigPath:any = load.lambda ? `${rootPath}/vk-configurations/secret.config.json` : `${rootPath}/routes/vk-configurations/secret.config.json`, localHistoryLambdaPath:any = load.lambda ? `${rootPath}/history_property-device-lambda` : `${rootPath}/routes/history_property-device-lambda`, SQSPath:any = load.lambda ? `${rootPath}/vk-configurations/sqsQueues.json` : `${rootPath}/routes/vk-configurations/sqsQueues.json`, SNSTopicsPath:any = load.lambda ? `${rootPath}/vk-configurations/snsTopics.json` : `${rootPath}/routes/vk-configurations/snsTopics.json`, secretConfig: any = require(secretConfigPath), SQS: any = require(SQSPath), SNSTopic = require(SNSTopicsPath) ; //import local modules import { StandardQueue } from "@virtualkey/vk-helper-sqs"; import {SNS} from "@virtualkey/vk-helper-sns"; import { DeviceSQS } from "../Interfaces/interfaces"; export class SqsHelper{ private standardQueue:StandardQueue; private sns:SNS; private accessKeyId= secretConfig.AWS_LAMBDA_CREDENTIALS.ACCESS_KEY_ID; private secretAccessKey= secretConfig.AWS_LAMBDA_CREDENTIALS.SECRET_ACCESS_KEY; private region= secretConfig.AWS_LAMBDA_CREDENTIALS.REGION; private topic = SNSTopic.error; private queue = SQS.QUEUES.PROPERTY_DEVICE_HISTORY; private wait = [1000,1000,1000,1000,1000]; private sqsMessage:any = {MessageBody:""} constructor(){ this.standardQueue = new StandardQueue(this.accessKeyId,this.secretAccessKey,this.queue,this.region); this.sns = new SNS(this.accessKeyId, this.secretAccessKey, this.topic, this.region ) } async sendDeviceMessageToSqs(payload:any){ console.log("Function started with payload222",payload); let bodyForSQS:DeviceSQS; try{ bodyForSQS = { propertyId:payload.propertyId, userId:payload.userId, deviceId:payload.deviceId, deviceInfo:payload.deviceInfo, deviceType:payload.deviceType, action:payload.action } //this code is added direct testing intead of lambda let local= false; try{ if(require(localHistoryLambdaPath)){ local = true; } }catch(err){} if(local){ let localHistoryLambda = require(localHistoryLambdaPath); await localHistoryLambda.handler(JSON.stringify(bodyForSQS)); } else { this.sqsMessage.messageBody = JSON.stringify(bodyForSQS); console.log(")))))))))) pushing message to sqs ((((((((((",JSON.stringify(this.sqsMessage)); const onError = async () => Promise.resolve() await this.standardQueue.sendMessage(this.sqsMessage, this.wait); console.log(")))))))))) pushed message to sqs (((((((((((("); } }catch(err){ console.log("fails to push code in sqs Impliment SNS here"); let subject = "Error in pushing code to SQS for device history"; await this.sns.send(subject,{ payload, err } ) } } }