未发送SQS消息

时间:2019-05-20 21:39:55

标签: javascript amazon-sqs

我有一个将项目添加到我的dynamo数据库的函数,并且我也希望它可以将项目发送到我的sqs队列,以便可以将其放入另一个lambda函数中。当我运行代码时,数据将被放入db中,但不会发送到队列中。我什至没有收到错误。

import * as dynamoDbLib from "./libs/dynamodb-lib";
import { success, failure } from "./libs/response-lib";
import AWS from 'aws-sdk';
const sqs = new AWS.SQS();

export async function main(event, context) {
  const data = JSON.parse(event.body);

  console.log(data);
  var site = "IE"+data.siteCounty+data.siteName;
  var siteIdStripped = site.replace(/[aeiou]/g, '');
  var siteId = siteIdStripped.replace(/ /g,'');
  var siteIdFinal = siteId.toUpperCase();

  const params = {
    "TableName": "sites",
    "Item": {
      userId: event.requestContext.identity.cognitoIdentityId,
      siteId: siteIdFinal,
      ...data,
      createdAt: Date.now()
    }
  };

  const messageParams = {
    MessageBody: params.Item,
    QueueURL: 'https://sqs.eu-west-1.amazonaws.com/106845550704/TranslateText'
  };

  function sendMessage(messageParams) {
    sqs.sendMessage(messageParams, (err, data) => {
      if (err) {
        console.log("Error: "+err);
      } else {
        console.log("Success: "+data.MessageId);
      }
    });
  }

  try {
    await dynamoDbLib.call("put", params);
    sendMessage(messageParams);
    return success(params.Item);
  } catch (e) {
    console.log(e);
    return failure({ status: false });
  }


}


0 个答案:

没有答案