This article is a supplement to the ServiceNow documentation. For full documentation please refer ServiceNow official website
Checkout our NEW Video Channel you can like and subscribe too!

Introduction

In this post we will do a POC to show how to integrate AWS and ServiceNow.The usecase is when we create a new EC2 instance in AWS then AWS SNS triggers a notification to ServiceNow. This notification finally creates a server in CMDB.

Overview

We are going to create a LAMP stack using AWS CloudFormation template.We will then use AWS Config to monitor any changes in the configuration of this server. SNS provides topics for pushing messages for these resources.When a change is detected by AWS Config then SNS is trigger which publishes the message to the topic which ServiceNow instance have subscribed to.

Steps followed

  1. Configure ServiceNow.
  2. Create an SNS topic and subscription.
  3. Confirm the SNS subscription in ServiceNow.
  4. Create a handler for the subscription in ServiceNow.
  5. Configure AWS Config.

Configure ServiceNow

  1. Log in to the developer instance.
  2. Navigate to
     System Applications > Studio
    

    awsintegraion050520201.PNG

  3. Click on Import From Source Control. awsintegraion050520202.PNG
  4. On the Import Application screen, enter the following details and Click on Import.
           URL: https://github.com/sayanawsit4/snow-aws.git
           User Name: Git hub user Name
           Password: Git hub password
    

    awsintegraion050520203.PNG

  5. Close the Studio browser tab.
  6. In the left Pane ,Navigate to SNS awsintegraion050520204.PNG

Create an SNS topic and subscription

Perform the following procedures to create an SNS topic and subscription:

  1. Log in to the SNS console, and select the US-East (N. Virginia) Region. awsintegraion050520205.PNG
  2. Click on services > type Simple in the search Box awsintegraion050520206.PNG
  3. Click on Simple Notification Service awsintegraion050520207.PNG
  4. Create a Topic awsintegraion050520208.PNG
  5. Give the topic a name, make the display name ServiceNow, and choose Create Topic. awsintegraion050520209.PNG awsintegraion0505202014.PNG
  6. Select the Amazon Resource Name (ARN) link for the topic that you just created. awsintegraion0505202010.PNG
  7. Choose Create Subscription. awsintegraion0505202011.PNG
  8. Choose HTTPS protocol. awsintegraion0505202012.PNG awsintegraion0505202013.PNG
     For Endpoint, use the service now administrator user id & password and 
     then enter the developer instance	link,which is rendered like the following:
     https://admin:<ServiceNow admin:password>@<your developer instance>.service-now.com/api/x_snc_aws_sns/aws_sns
     eg:https://admin:****@dev64666..service-now.com/api/x_snc_aws_sns/aws_sns
    
  9. Choose Create Subscription.

Your new subscription is pending confirmation.

Confirm the SNS subscription in ServiceNow

Before allowing SNS to send messages to ServiceNow, confirm the subscription on ServiceNow. At this point, AWS already sent a handshake request, which is awaiting confirmation inside your ServiceNow instance.

  1. Navigate to SNS in the service now instance > Subscriptions. awsintegraion0505202015.PNG
  2. Notice that AWS created a new record. awsintegraion0505202016.PNG
  3. Open the subscription by choosing ServiceNow, then choose Confirm Subscription.

Create a handler for the subscription in ServiceNow

Now, set up ServiceNow to be able to absorb received messages from AWS. Create a handler that’s able to create a new record in the CMDB Server table (cmdb_ci_server) whenever a new EC2 instance is created from a sample AWS CloudFormation stack.

To set up the handler, follow these steps:

  1. At the bottom of the Subscriptions form, for Handler Related list , choose New and then provide a name for the handler,such as Create CMDB Server from EC2. awsintegraion0505202017.PNG
  2. Enter the following code inside the function: awsintegraion0505202018.PNG
      var webserver = new GlideRecord("cmdb_ci_server"); 
      webserver.initialize(); 
      webserver.name = "AWS WebServer "+message.configurationItem.configuration.launchTime ; 
      webserver.short_description = "Monitoring is "+message.configurationItem.configuration.monitoring.state+" and Instance Type is "+message.configurationItem.configuration.instanceType ; 
      webserver.asset_tag = message.configurationItem.configuration.instanceId ; 
      webserver.insert();
  

Choose Submit

Configure AWS Config

  1. Click on services > type config in the search Box awsintegraion0505202019.PNG
  2. Select Config
    awsintegraion0505202020.PNG
  3. In the left navigation pane, choose Settings. awsintegraion0505202021.PNG
  4. For Recording, make sure that the value is On. Under Resources Type to Record, for All Resources, select both check boxes:
    • *Record all resources supported in this region
    • *Include global resources (including IAM resources) awsintegraion0505202022.PNG
  5. Choose Choose a topic from your account. awsintegraion0505202023.PNG
  6. Choose Save. awsintegraion0505202024.PNG

AWS SNS policy update

  1. Click on services > type Simple in the search Box awsintegraion050520206.PNG
  2. Click on Simple Notification Service awsintegraion050520207.PNG
  3. In the left navigation pane, choose Topics awsintegraion0505202025.PNG
  4. Select your topic awsintegraion0505202026.PNG
  5. click on Edit awsintegraion0505202029.PNG
  6. Go to Access Policy awsintegraion0505202030.PNG
  7. Update the code as below awsintegraion0505202031.PNG
      {
      "Version": "2008-10-17",
      "Id": "__default_policy_ID",
      "Statement": [
        {
          "Sid": "__default_statement_ID",
          "Effect": "Allow",
          "Principal": {
            "AWS": "*"
          },
          "Action": [
            "SNS:GetTopicAttributes",
            "SNS:SetTopicAttributes",
            "SNS:AddPermission",
            "SNS:RemovePermission",
            "SNS:DeleteTopic",
            "SNS:Subscribe",
            "SNS:ListSubscriptionsByTopic",
            "SNS:Publish",
            "SNS:Receive"
          ],
          "Resource": "*"
        }
      ]
    }
   

click on Save Changes awsintegraion0505202032.PNG

Testing the integration

You can test this integration by creating a stack from the AWS CloudFormation sample templates, which trigger recording in AWS Config. This process then creates SNS notifications, which creates a configuration item in the ServiceNow CMDB.

  1. In the AWS CloudFormation console, choose Create stack.
  2. Select a sample template.
  3. Under Specify Details, enter the following information:
  4. Choose Next.
  5. In the left navigation pane, choose Options, provide tags if needed, and then choose Next.
  6. At the bottom of the review page, choose Create. Wait for the stack creation to complete. 8.Navigate to ServiceNow, then Server to check whether a server was created.

If you see a new server entry, you successfully integrated AWS Config with the ServiceNow CMDB.

    Content