ServiceNow Integration with AWS Lambda

nivethika
Tera Contributor

Hi All,

I have one doubt in doing this task. from snow side  what all i have to do for this usecase.

Invoke Lambda, This lambda will make REST API Call to SNOW to create Incident ticket
When SNOW Admin approves this ticket, then snow has to make REST API Call from SNOW Script, this has to invoke our API Gateway Endpoint (REST API) by passing incident ticket, from there, invoke Lambda, this lambda will start deploy.

(i.e)using a Lambda we will create a Incident Ticket in SNOW and the user will also get an email, The SNOW user has to sign in and Approve the ticket, which will call a AWS API Gateway Endpoint, which will internally a Lambda to continue with the CICD pipeline process(deployment).

Please help me to understand and solve this issue.

 

Thanks & Regards,

Nivethika

1 ACCEPTED SOLUTION

Bhaba
Tera Expert

ServiceNow Integration with AWS Lambda:

1.      The first step is to create a Lambda function in AWS.

Navigate to Lamba>Create Function

find_real_file.png

2.      In Function Code, you have options to code entry type as:

  • Edit Code inline
  • Upload a zip fie
  • Upload a file from S3

I have selected Edit code inline for now for the simple demonstration

Then select the Runtime you want to run in and the handler information.

Handler should be of the definition lambda_function_file_name.method_name

So, for example, here, my python file name is lambda_function and method is lambda_handler.

find_real_file.png

3.      Then, type the code and analysis you wish to perform. In the example, I am retrieving the input from API call and returning the output after concatenating the string ā€˜something’ to it.

def lambda_handler(event, context):

   short_desc=event['params']['querystring']['token'];     //accessing the parameters from api call

   return 'something'+short_desc

4.       Then, type the code and analysis you wish to perform. In the example, I am retrieving the input from API call and returning the output after concatenating the string ā€˜something’ to it.

5.      Create an execution role with accessing permissions to Lambda and save the function.

6.      Now, select the API Gateway as the trigger and by default, ANY method is available in the Method Execution.

find_real_file.png

7.      Add the GET method or any other method you wish to call the Lambda function through your API calls.

find_real_file.png

8.      Now for accessing the parameters from the API query/call, you need to set up the Integration Request for GET method as shown below:

find_real_file.png

Note: The Body Mapping Template has to be defined and saved which passes all the parameters to the integration endpoint and can be accessed in the Lambda functions using ā€˜event’ variable. There are different ways to accomplish this (like Lambda proxy integration) and this is one of the fast and easy ways.

9. Now, it is ready to invoke the url and trigger the respective Lambda function. The invoke url is found at Stages>GET method.

find_real_file.png

10.  Lastly, click the API and Select Actions>Deploy API.

ServiceNow REST Message creation

1.      Navigate to System Web Services>REST Message>New.

find_real_file.png

2. Fill in the form with a name and endpoint(url from aws lambda). If you want to send parameters, insert them in the endpoint like

https://eqtknizmg4.execute-api.us-east-1.amazonaws.com/start/myLambdaFunction?token=${token}

 3. The GET method is added by default in the HTTP method and add the variables (in this case ā€˜token’) in the Variable Substitutions column and give a test value.

4.      Finally, test the Rest Message by clicking the Test Related Link and the output is in the Response field.

find_real_file.png

Following these steps, you can successfully create ServiceNow integration with AWS Lambda.

If you've any difficulty in understanding, please let me know. Also, share your feedback after successful integration.

Thank you.

View solution in original post

4 REPLIES 4

Bhaba
Tera Expert

ServiceNow Integration with AWS Lambda:

1.      The first step is to create a Lambda function in AWS.

Navigate to Lamba>Create Function

find_real_file.png

2.      In Function Code, you have options to code entry type as:

  • Edit Code inline
  • Upload a zip fie
  • Upload a file from S3

I have selected Edit code inline for now for the simple demonstration

Then select the Runtime you want to run in and the handler information.

Handler should be of the definition lambda_function_file_name.method_name

So, for example, here, my python file name is lambda_function and method is lambda_handler.

find_real_file.png

3.      Then, type the code and analysis you wish to perform. In the example, I am retrieving the input from API call and returning the output after concatenating the string ā€˜something’ to it.

def lambda_handler(event, context):

   short_desc=event['params']['querystring']['token'];     //accessing the parameters from api call

   return 'something'+short_desc

4.       Then, type the code and analysis you wish to perform. In the example, I am retrieving the input from API call and returning the output after concatenating the string ā€˜something’ to it.

5.      Create an execution role with accessing permissions to Lambda and save the function.

6.      Now, select the API Gateway as the trigger and by default, ANY method is available in the Method Execution.

find_real_file.png

7.      Add the GET method or any other method you wish to call the Lambda function through your API calls.

find_real_file.png

8.      Now for accessing the parameters from the API query/call, you need to set up the Integration Request for GET method as shown below:

find_real_file.png

Note: The Body Mapping Template has to be defined and saved which passes all the parameters to the integration endpoint and can be accessed in the Lambda functions using ā€˜event’ variable. There are different ways to accomplish this (like Lambda proxy integration) and this is one of the fast and easy ways.

9. Now, it is ready to invoke the url and trigger the respective Lambda function. The invoke url is found at Stages>GET method.

find_real_file.png

10.  Lastly, click the API and Select Actions>Deploy API.

ServiceNow REST Message creation

1.      Navigate to System Web Services>REST Message>New.

find_real_file.png

2. Fill in the form with a name and endpoint(url from aws lambda). If you want to send parameters, insert them in the endpoint like

https://eqtknizmg4.execute-api.us-east-1.amazonaws.com/start/myLambdaFunction?token=${token}

 3. The GET method is added by default in the HTTP method and add the variables (in this case ā€˜token’) in the Variable Substitutions column and give a test value.

4.      Finally, test the Rest Message by clicking the Test Related Link and the output is in the Response field.

find_real_file.png

Following these steps, you can successfully create ServiceNow integration with AWS Lambda.

If you've any difficulty in understanding, please let me know. Also, share your feedback after successful integration.

Thank you.

SK5555
Tera Contributor

could you please let me know what are the steps to create a function in lambda

SK5555
Tera Contributor

Can I get free lambda account for demo