简体   繁体   中英

Unable to trigger aws sqs from aws lambda function

I have an aws lambda function that needs to trigger an aws sqs but I always get the following message:

Fail Send MessageAccessDenied: Access to the resource https://sqs.eu-west-1.amazonaws.com/ is denied

This is my lambda:

var QUEUE_URL = 'https://sqs.eu-west-1.amazonaws.com/*****/*****'
var AWS = require('aws-sdk');
var sqs = new AWS.SQS({region : 'eu-west-1'});


exports.handler = function(event, context) {

  var params = {
    MessageBody: JSON.stringify(event),
    QueueUrl: QUEUE_URL
  };
  sqs.sendMessage(params, function(err,data){
    if(err) {
      console.log('error:',"Fail Send Message" + err);
      context.done('error', "ERROR Put SQS");  // ERROR with message
    } else{
      console.log('data:',data.MessageId);
      context.done(null,'');  // SUCCESS
    }
  });
}

Anybody any idea what the problem could be or a good resource for the aws.sqs? Do I need to pass credentials, and how do I set my queue url in aws.sqs?

Do you have an execution role assigned to your Lambda function that allows it to send a message to the SQS queue? This article details how to do it, specifically the section, Setting up the IAM Role.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM