我在使用SQS的AWS ElasticBeanstalk Worker时遇到问题。我已经阅读了很多资源并对其进行了实验,但仍然无法成功地将工作者与SQS连接起来。
使用带有Hapi的Node.js创建作为使用者的工作者。我在本地计算机上使用CURL测试了这个脚本,效果很好。
var Hapi = require('hapi');
var Good = require('good');
var server = new Hapi.Server();
server.connection({
port: process.env.PORT || 3000
});
server.route({
method: 'POST',
path: '/hello',
handler: function (request, reply) {
console.log('CIHUUY response: ', request.payload);
reply();
}
});
server.register({
register: require('good'),
options: {
reporters: [{
reporter: require('good-console'),
events: { log: '*', response: '*' }
}]
}
}, function (err) {
if (err) {
console.error(err);
}
else {
server.start(function () {
console.info('Server started at ' + server.info.uri);
});
}
});
我的工作人员的IAM政策
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "QueueAccess",
"Action": [
"sqs:ChangeMessageVisibility",
"sqs:DeleteMessage",
"sqs:ReceiveMessage",
"sqs:SendMessage"
],
"Effect": "Allow",
"Resource": "*"
},
{
"Sid": "MetricsAccess",
"Action": [
"cloudwatch:PutMetricData"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
对于队列,我设置了允许每个人访问它的权限。我给它起了一个名字 testingqueue
对于工作人员配置
我检查了日志 /var/log/nodejs/nodejs.log
^[[1;33mpost^[[0m /hello {} ^[[33m400^[[0m (2ms)
150701/094208.444, [response], http://ip-10-142-107-58:8081: ^[[1;33mpost^[[0m /hello {} ^[[33m400^[[0m (1ms)
150701/094208.773, [response], http://ip-10-142-107-58:8081: ^[[1;33mpost^[[0m /hello {} ^[[33m400^[[0m (2ms)
150701/094208.792, [response], http://ip-10-142-107-58:8081: ^[[1;33mpost^[[0m /hello {} ^[[33m400^[[0m (1ms)
150701/094208.882, [response], http://ip-10-142-107-58:8081: ^[[1;33mpost^[[0m /hello {} ^[[33m400^[[0m (1ms)
150701/094208.951, [response], http://ip-10-142-107-58:8081: ^[[1;33mpost^[[0m
我还检查了awssqsd日志 /var/log/aws-sqsd/default.log
2015-07-01T09:44:40Z http-err: 75704523-42de-40de-9f9f-8a59eb3fb332 (7324) 400 - 0.004
2015-07-01T09:44:40Z message: sent to %[http://localhost:80]
2015-07-01T09:44:40Z http-err: 59e2a75b-87f7-4833-8cde-11900d48a7c5 (3770) 400 - 0.007
2015-07-01T09:44:40Z message: sent to %[http://localhost:80]
2015-07-01T09:44:40Z http-err: e2acb4e0-1059-4dc7-9101-8d3e4c974108 (7035) 400 - 0.003
2015-07-01T09:44:40Z message: sent to %[http://localhost:80]
2015-07-01T09:44:40Z http-err: 04d2436a-0b1e-4a1f-8826-a2b30710f569 (9957) 400 - 0.005
我一直收到错误400.我很好奇为什么它无法连接。
我做过的事情:
任何人都可以在这里帮助我
谢谢
答案 0 :(得分:0)
您的代码没有任何问题。我只是毫不费力地将它传送到AWS。
/var/log/nodejs/nodejs.log
Server started at http://myIP:8081
CIHUUY response: { test: 'testvalue' }
151118/110150.862, [response], http://myIP:8081: [1;33mpost[0m /hello {} [32m200[0m (38ms)
/var/log/aws-sqsd/default.log
2015-11-18T10:58:38Z init: initializing aws-sqsd 2.0 (2015-02-18)
2015-11-18T10:58:39Z start: polling https://sqs.us-west-2.amazonaws.com/myaccountname/awseb-e-mnpfjxiump-stack-AWSEBWorkerQueue-1FPDK4Z8E3WRX
2015-11-18T11:01:50Z message: sent to %[http://localhost:80]
正如您所看到的,我收到了测试消息。唯一的区别是可以看到我有自动生成的队列,但这应该不是问题,因为你的日志显示恶魔从队列中获取消息并转发它。我使用与你的工人相同的政策。