Reputation: 515
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?
Upvotes: 1
Views: 1674
Reputation: 1577
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.
Upvotes: 3