Integration with Amazon SQS - how to import AWS SDK or CryptoJS libraries for server side coding?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2016 06:49 AM
I have a requirement to post a message on to AWS SQS when a certain type of incident occurs. The message payload is in a JSON format, and I have an ACCESS KEY, a SECRET KEY, a username and of course the AWS REGION and URL. What I can't figure out is how to build the v4 signature required to submit a message to AWS SQS.
Does anyone have insight on how to import either the AWS SDK or the CryptoJS libraries into ServiceNow in such a way that they can be used server-side to create such a message?
I attempted the method outlined in Mini-Lab: Adding Underscore.js Into ServiceNow without success, getting a Javascript parse error that prevents the library from being saved.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 08:59 AM
Hi Josh,
I wanted to use the NodeJs "crypto" module.
what is the way same crypto module as JS class in ServiceNow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2017 06:23 AM
I used the same "stub" code I posted in the thread and after running webpack, here are the modifications I had to make:
(Line numbers may not be exact)
Line 6363
Before:
CipherBase.prototype.final = function (outputEnc) {
After:
CipherBase.prototype._final = function (outputEnc) {
Explanation: 'final' is a reserved word in the JS engine ServiceNow is using. This was causing the Script field validator to throw an error. I searched through the code and this method isn't actually used anywhere, so I just gave it a _ prefix. If it was used throughout, it would have been necessary to update any references.
Line 3855
Before:
exports.decode = exports.parse = __webpack_require__(11);
exports.encode = exports.stringify = __webpack_require__(12);
After:
exports.decode = exports.parse = __webpack_require__(11);
exports.encode = exports.stringify = __webpack_require__(12);
exports.escape = exports.encode; // NEW
exports.unescape = exports.decode; // NEW
Explanation: This looks like a bug in the aws4 library — at some time in the past, the escape/unescape methods must have existed in the 'querystring' node module, but they were renamed. To make things work, I just made copies of them so the code would function.
These were the only modifications I had to make, and I was able to successfully save the code in a script include and make calls to SQS using RESTMessageV2.
I posted a working example on Share here: https://share.servicenow.com/app.do#/detailV2/6e87c240db34360010c37ecfbf961979/overview
Disclaimer: No warrantee about the functionality or readiness for a production environment, this is purely for reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2017 06:41 AM
Thank you very much for the input!!!! I will attempt those modifications at my earliest opportunity (we're still testing through the Helsinki upgrade, but this is on my list of items to validate!)
Thanks!
Tamara
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-08-2018 07:26 AM
@tamarasylte : Were able to implement SN and AWS SQS integration?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2021 09:29 AM
I am trying to execute the example from share in ORLANDO on the scripts background and I get an error:
ReferenceError: "aws4" is not defined.
This is the core I run:
try {
var sqs = new x_aws_sigv4.SQSClient();
sqs.sendMessage({
QueueUrl: 'https://sqs.us-east-2.amazonaws.com/012385612815123/testing',
MessageBody: 'Hello from SQSClient on SERVICENOW',
});
}catch(e){
gs.info(e);
}
I am not sure how to invoke the aws4 script include from the SQSClient script include. Can you help?