I'm setting up the serverless framework to be able to push some messages to AWS SQS and everything is working up until the sqs.sendMessage logic and I can't seem to figure out what's going on. It gets to it and just dies, no error or anything.
I've tried a variety of configurations within serverless, and tried giving the SQS queue full rights to anyone for all SQS functions, none of that worked.
Serverless.yml
service: hook
provider:
name: aws
runtime: nodejs10.x
stage: ${opt:stage, 'local'}
region: ${opt:region, 'us-east-1'}
iamRoleStatements:
- Effect: "Allow"
Action:
- "sqs:SendMessage"
- "sqs:GetQueueUrl"
Resource:
Fn::GetAtt:
- HookQueue
- Arn
- Effect: "Allow"
Action:
- "sqs:ListQueues"
Resource:
Fn::GetAtt:
- HookQueue
- Arn
functions:
hookListener:
handler: handler.hook
events:
- http:
path: hook
method: post
environment:
SQS_URL:
Ref: HookQueue
resources:
Resources:
HookQueue:
Type: "AWS::SQS::Queue"
Properties:
QueueName: "HookQueue-${opt:stage, 'local'}"
Handler.js
'use strict';
var AWS = require('aws-sdk');
var sqs = new AWS.SQS({
region: 'us-east-1'
});
module.exports.hook = (event, context, callback) => {
console.log(event);
var eBody = JSON.parse(event.body);
var queueUrl = process.env.SQS_URL;
console.log('SQS url is: ' + queueUrl);
var realmID = 1234
console.log('attempting to store: ' + realmID + ' body: ' + event.body);
var params = {
MessageBody: JSON.stringify({ realmID: realmID,
entities: event.body}),
QueueUrl: queueUrl
};
console.log('got here');
//Send message to SQS queue
sqs.sendMessage(params, function(err, data) {
if (err) {
console.log('error:', "failed to send message" + err);
callback(null, {statusCode: 500, body: 'Internal Service Error'});
} else {
console.log('data:' + data.MessageId);
console.log('Sent to ' + queueUrl);
console.log(data.MessageId);
}
console.log('after the send logic');
});
callback(null, {statusCode: 200, body: 'Success'});
};
Looking for any suggestions, thanks!
asyncfrom the handler declaration.handler: handler.hook!=quickhook.