Skip to content

Instantly share code, notes, and snippets.

@carlok

carlok/index.js Secret

Created April 18, 2017 15:09
Show Gist options
  • Save carlok/c008a1705ae17f5350a42235be6fbe15 to your computer and use it in GitHub Desktop.
Save carlok/c008a1705ae17f5350a42235be6fbe15 to your computer and use it in GitHub Desktop.
Broken AWS SQS Hapi Plugin example
'use strict';
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 8000
});
server.register([
{
register: require('hapi-aws'),
options: {
global: {
accessKeyId: '...',
secretAccessKey: '...',
region: 'eu-central-1'
},
services: [{
name: 'SQS',
service: 'SQS',
options: {
apiVersion: '2012-11-05'
}
}]
}
}
], (err) => {
(err !== undefined) ? console.log(err) : null;
});
// Add the route
server.route({
method: 'GET',
path: '/hello',
handler: function (request, reply) {
const params = {
DelaySeconds: 10,
MessageAttributes: {
"Title": {
DataType: "String",
StringValue: "The Whistler"
},
"WeeksOn": {
DataType: "Number",
StringValue: "6"
}
},
MessageBody: "5...",
QueueUrl: 'https://sqs.eu-central-1.amazonaws.com/...'
};
server.plugins['hapi-aws'].SQS.sendMessage(params).promise()
.then(function (data) {
console.log('Success', data.MessageId);
}).catch(function (err) {
console.log(err, err);
});
return reply('hello world');
}
});
// Start the server
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment