-
-
Save carlok/c008a1705ae17f5350a42235be6fbe15 to your computer and use it in GitHub Desktop.
Broken AWS SQS Hapi Plugin example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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