0

Unable to get AWS Lambda to send message to an SQS Queue. I have removed the ids from the queue URL. The code doesn't fail but also doesn't send any message.

    var AWS = require('aws-sdk');
    
    
    exports.handler = async (event) => {
      
      process.env['AWS_ACCESS_KEY_ID'] = process.env['AWS_ACCESS_KEY_ID_VAL'];
      process.env['AWS_SECRET_ACCESS_KEY'] = process.env['AWS_SECRET_ACCESS_KEY_VAL'];
      process.env['AWS_REGION'] = process.env['AWS_REGION_VAL'];
    
    console.log("11")
    AWS.config.update({region: 'ap-southeast-2'});
    
    // Create an SQS service object
    var sqs = new AWS.SQS({apiVersion: '2012-11-05'});
    console.log("22")
    
    var params = {
      MessageBody: "This is a test message",
      QueueUrl: "https://sqs.ap-southeast-2.amazonaws.com/11111111111/the-queue-name"
    };
    console.log("33")
    var outcome = await sqs.sendMessage(params, await function(err, data) {
      
      console.log("logging here")
      
      if (err) {
        console.log("Error", err);
      } else {
        //Log successful result id
        console.log("Success", data.MessageId);
      }
    });        
  };
1
  • Did you check the Cloudwatch logs for the function? Commented Aug 7, 2021 at 0:38

1 Answer 1

2

You will need promise() at the end of await sqs.sendMessage like this:

await sqs.sendMessage(
...
).promise();

Ref: Example index.js file – AWS SDK with async handler and promises https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html#nodejs-handler-async

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.