Create Incident High Priority Tickets in Servicenow with the Click of Amazon Dash Button
Following things are required to get started
-
- Goto www.servicenow.com and Register for Free Development Instance
- Goto https://aws.amazon.com/ and register for AWS Account
- Buy Amazon Iot Button from Amazon website
Once you purchase the Amazon Dash Button we have to register that button into AWS Account which you created Above
TWO WAYS TO DO IT…VERY IMPORTANT !!!!!!!!!!!!!!!!!!
- Through Mobile Application ( Always Preferrable – Saves time – Makes Policy Private key and Certificates Automatically)
- Through AWS Console Manually ( We have to make all of them Individually)
Mobile Application
Registration of Dash with Mobile Phone either on Android or Iphone. Download the Amazon IoT App
The fastest way to start using your AWS IoT Button is to download the mobile app for iOS or Android. The mobile app creates the required AWS IoT resources for you, and adds an event source to your button that uses a Lambda blueprint to invoke a new AWS Lambda function of your choice. Blueprints are preconfigured Lambda functions that allow you to quickly connect the click of a button to the functions that fit you best, such as sending automated emails or text messages or deploying other AWS services. You can download the mobile apps from App Store or Google Play Store
Open the application
- You can login the application through your AWS Credentials which you created in the previous Step
- Click on “Agree & Get Started” to Register your device
once you do it follow the on-screen steps where in you will be prompted to press your dash button for 5 seconds to register your device with WiFi Network
Give about 5-30mins after you register from mobile device to show up on your aws console
- Login to AWS Console (https://aws.amazon.com) and goto IOT-Core and then goto “Manage” you will see the Amazon dash button which you registered over there. Check below screenshot
Advantage of registering through Mobile phone is that you dont need to Manually Create Certificate, Private key and Policy to register your device
Register Amazon Dash by Amazon Console
Register a Device in the Registry
Devices connected to AWS IoT are represented by things in the registry. The registry allows you to keep a record of all of the devices that are connected to your AWS IoT account.
If you are unable to use the mobile apps, follow these instructions.
To register your device in the registry:
- Login to http://aws.amazon.com
- Click on “All Services” and find for IOT-Core
Click on IoT Core and it will open the AWS Iot Screen like below. Click on “Manage”
After clicking on “Manage” you can click on Create on the window which opens or you can click on “Register a Thing”
Click on “Create Single Thing”
On the Create a thingpage, in the Name field, type a name for your device, such as MyIoTButton. Choose Next to add your device to the registry
Create and Activate a Device Certificate
Communication between your device and AWS IoT is protected through the use of X.509 certificates. AWS IoT can generate a certificate for you or you can use your own X.509 certificate. In this tutorial, AWS IoT generates the X.509 certificate for you. Certificates must be activated prior to use.
- Choose Create certificate
- On the Certificate created! page, choose Download for the certificate, private key, and the root CA for AWS IoT (the public key need not be downloaded). Save each of them to your computer, and then choose Activate to continue.
Be aware that the downloaded filenames may be different than those listed on the Certificate created! page. For example:
-
- 2a540e2346-certificate.pem.crt.txt
- 2a540e2346-private.pem.key
- 2a540e2346-public.pem.key
Note
Although it is unlikely, root CA certificates are subject to expiration and/or revocation. If this should occur, you must copy new a root CA certificate onto your device.
- Choose the back arrow until you have returned to the main AWS IoT console screen.
Create an AWS IoT Policy
X.509 certificates are used to authenticate your device with AWS IoT. AWS IoT policies are used to authorize your device to perform AWS IoT operations, such as subscribing or publishing to MQTT topics. Your device will presents its certificate when sending messages to AWS IoT. To allow your device to perform AWS IoT operations, you must create an AWS IoT policy and attach it to your device certificate.
To create an AWS IoT policy:
In the left navigation pane, choose Secure, and then Policies. On the You don’t have a policy yet page, choose Create a policy.
On the Create a policy page, in the Name field, type a name for the policy (for example,MyIoTButtonPolicy). In the Action field, type iot:Connect. In the Resource ARN field, type *. Select the Allow checkbox. This allows all clients to connect to AWS IoT.
Note
You can restrict which clients (devices) are able to connect by specifying a client ARN as the resource. The client ARNs follow this format:
arn:aws:iot:your-region:your-aws-account:client/<my-client-id>
Select the Add Statement button to add another policy statement. In the Action field, type iot:Publish. In the Resource ARN field, type the ARN of the topic to which your device will publish.
Note
The topic ARN follows this format:
arn:aws:iot:your-region:your-aws-account:topic/iotbutton/your-button-serial-number
For example:
arn:aws:iot:us-east-1:123456789012:topic/iotbutton/G030JF055364XVRB
You can find the serial number on the bottom of your button.
If you are not using an AWS IoT button, after topic/ in the ARN, place the topic your device publishes to. For example:
arn:aws:iot:us-east-1:123456789012:topic/my/topic/here
Finally, select the Allow check box. This allows your device to publish messages to the specified topic.
After you have entered the information for your policy, choose Create.
Attach an AWS IoT Policy to a Device Certificate
Now that you have created a policy, you must attach it to your device certificate. Attaching an AWS IoT policy to a certificate gives the device the permissions specified in the policy.
In the left navigation pane, choose Secure, and then Certificates.
In the Attach policies to certificate(s) dialog box, select the check box next to the policy you created in the previous step, and then choose Attach.
Attach a Certificate to a Thing
A device must have a certificate, private key and root CA certificate to authenticate with AWS IoT. We recommend that you also attach the device certificate to the thing that represents your device in AWS IoT. This allows you to create AWS IoT policies that grant permissions based on certificates attached to your things. For more information. see Thing Policy Variables
To attach a certificate to the thing representing your device in the registry:
In the box for the certificate you created, choose to open a drop-down menu, and then choose Attach thing.
In the Attach things to certificate(s)dialog box, select the check box next to the thing you registered, and then choose Attach.
To verify the thing is attached, select the box representing the certificate.
On the Details page for the certificate, in the left navigation pane, choose Things.
To verify the policy is attached, on the Detailspage for the certificate, in the left navigation pane, choose Policies.
As now you might have understood how painful it is to do all these Manual steps where as if you register through your phone Device its a piece of Cake.
Always Recommended Use MOBILE PHONE TO REGISTER DASH DEVICE TO AWS!!!!!!!!
The real fun starts now—Integrating with Servicenow
- From AWS Console type “Lamda” into the sevices
- Click on “Create Function”
- Click on “Author from Scratch”
- Name: Give any function name ( I gave XYZ)
- Runtime: Nodejs.4.3
- Role: Choose existing or create new ( doesn’t matter)
- Your screen will look like below.
- Click on the Brown from the screen. You will see below the development workspace which we will configure to create Incidents in servicenow.
Note: This has nothing to do with Dash Button. This is simply creating integration between Lamda Function and Servicenow. We will configure the trigger later
- In the function code section Select the “Code Entry Type” Upload a zip File
- Upload the zip file which we have provided to you
- After you are done with upload your screen should look like below
You would need to provide your
- Servicenow instance URL
- User ID and pwd
- JSON Parameters
In the URL from the Indes.js Code you can write down the Rest API to create incidents from Servicenow.
please use REST API Explorer Feature in Servicenow to figure out the REST API.
in my case i have used http://instanceURL/api/now/incident
Please check below Code which i have used in the Index.js
‘use strict’;
exports.handler = (event, context, callback) => {
console.log(‘Received event:’, event.clickType);
var request = require(‘request’);
var options = { var options = { uri: ‘https://InstanceURL.com/api/now/table/incident’,
method: ‘POST’,
auth: { //SN username and password username: ‘admin’, password: ‘ryder123’ },
json:
{ “impact”:”1″,
“urgency”:”1″,
“short_description”:”My First Iot Project” }
};
request(options, function (error, response, body)
{ if (!error && response.statusCode == 200) { console.log(body.id); }
else { console.log(‘error : ‘+ error); } });
};
After you finish putting the Servicenow credentials please follow Above steps
Go up and click on “AWS Iot” as per screenshot and then we need configure it
Click on the AWS IoT which is next to blue icon so that we can configure the trigger
Follow the steps:
Put the Device serial Number and click on Generate Certificate and Keys
- Please follow below steps as per screenshot
Your details might be different then in screenshot after you enable trigger
And the click here means the following URL
now your screen will look like below
Make sure you hit “Save”
Click on test and test to see if its creating incident in servicenow
Success Message
Login to Servicenow Instance and click on Incidents–>Open
Please email me at Nikunjbambharolia@gmail.com if you the files for the Code to be inserted into the Lambda Function. I will send you within 24hours after your Email
Please provide Feedback if you Enjoyed this Experiment.
Cheers!!