AWS for SAP
Run business queries to SAP with Amazon Pinpoint through Short Message Service (SMS)
SAP customers are looking to consume the outputs of business processes enabled by SAP and non-SAP applications for their own users, their partners and their employees through multiple channels. Channels that are beyond web applications and mobile apps.
In this blog, we will look at the process of creating a SMS-based chatbot for SAP using Amazon Lex and Amazon Pinpoint. Amazon Lex is a service for building conversational interfaces and Amazon Pinpoint is a service that you can use to engage with your customers across multiple messaging channels like email, SMS, push, or voice.
A major advantage of using Amazon Pinpoint for customer engagement workflows is its ability to integrate tightly with other AWS services. These integration makes it possible to engage in personalized conversations with users. Another advantage of SMS chat bot is to use it in areas where quality of internet connectivity is not satisfactory.
Overview
In this blog, we will explore the process of integrating SAP business processes with Amazon Pinpoint and Amazon Lex. We will create a chatbot that will help users to retrieve available sales orders directly from a SAP ERP or S/4HANA system using two-way SMS through Amazon Pinpoint. Lex will provide the interactive chatbot back end to Pinpoint, and Pinpoint will send and receive messages through SMS. AWS Lambda will connect these two services together. Another Lambda function will connect the Lex-based chatbot to the backend SAP System. The following image illustrates the architecture and process flow of this integration, that we will create in this blog.
Below are configuration steps that we will perform as the part of this blog.
- Expose data from SAP system
- Set up the Lambda to read data from SAP
- Create a Lex chatbot
- Set up a project in Amazon Pinpoint
- Set up the Lambda to connect with Amazon Pinpoint
- Test the chatbot
Step 1: Expose data from SAP
SAP Gateway enables SAP applications to share data with a wide range of devices, technologies, and platforms in a way that is easy to understand and consume by exposing SAP Business-Suite functionality through REST-based OData (Open Data Protocol) services. OData is a Web protocol for querying and updating data, applying and building on Web technologies such as HTTP/HTTPS. OData is easy to understand and extensible, and provides consumers with a predictable interface for querying a variety of data sources. SAP Gateway uses OData to consume SAP business data, such as descriptions of fields that can be retrieved from the SAP ABAP Dictionary. For this blog, we have created an OData service to fetch Sales Order details from SAP S/4HANA environment running on AWS. There are many other useful OData operations that could be built, such as fetching material master table records, fetching plant details and fetching material details based on plant.
Below is a screenshot of SAP Gateway Client that shows fetch Sales Order OData service.
Step 2: Set up an AWS Lambda function to read data from SAP
After you have created your SAP OData service, create a Lambda function that allows you to read and write data from SAP Odata service.
To create the Lambda function
-
- Sign in to the Lambda console
- Create a new Python 3.6 function from scratch. Create a new IAM role with the default permissions. For more information about creating functions, see Lambda documentation.
- Store the username, password of SAP and URL of the SAP OData service in AWS Secrets Manager
- Now, we will encode SAP credentials that are stored in AWS Secrets Manager and pass them via a python request module to the SAP S/4HANA system in the request header. First, we will fetch the username, password and URL of the SAP system that are stored in AWS Secrets Manager.
# Specify name of recently created AWS Secret and AWS region secret_name = "<secret name>" region_name = "<region id>" # Create a Secrets Manager client session = boto3.session.Session() client = session.client(service_name='secretsmanager',region_name = region_name) # Get secret from secrets manager get_secret_value_response = client.get_secret_value(SecretId=secret_name) secret = json.loads(get_secret_value_response['SecretString']) # fetch SAP details from secrets manager username = secret["username"] password = secret["password"] URL = secret["url"]
5. Now, we will encode this information in the HTTP get request header and store output of this request in JSON format in a variable SapOdataOutputJson.
# pass username and password from secret to request userAndPass = secret["username"]+":"+secret["password"] userAndPass_encode = userAndPass.encode('ascii') userAndPass_decode = b64encode(userAndPass_encode).decode('ascii') # Create HTTP header and perform get request to SAP system headers = { 'Authorization' : 'Basic %s' % userAndPass_decode } ODataRequest = requests.get(url = URL, headers=headers)
6. The response of the get request is saved in JSON format and then traversed through that output to get answers to various chatbot queries which we will show later using Amazon Pinpoint SMS channel.
SapOdataOutputJson = ODataRequest.json()
7. Save this lambda as SapSalesOrderCheck. In the next step, we will explore how the chatbot invokes this function to get data out of SAP system.
Step 3: Create an Amazon Lex chatbot
Now it’s time to create the bot. We will create a Lex bot to handle SMS queries and respond with data from the SAP system. For this blog, we will use a limited number of intents. Later, you can customize this bot to fit your requirements by specifying additional intents.
To create your bot
- Open the Lex console.
- Create a new bot. On the Create your bot page, choose ‘Custom Bot’. Use the default IAM role. For COPPA , choose No. Note the name that you specified for the bot—you need to refer to this name in the Lambda function that you create later in step 6. For more information about creating bots in Lex, see Lex documentation.
- When the bot is built, choose Publish. For Create an alias, enter latest. Choose Publish.
- Below is snippet of our Lex bot sapbp which answers questions like “Check buyer name” or “What is gross Amount”, or “Tax for given Sales Order number”. As you can see this Lex bot invokes Lambda function SapSalesOrderCheck. that we have created in step 2 above to read data from the SAP system.
- In the next steps, we will create a new Pinpoint project and one more Lambda function that can send and receive SMS messages from this Lex Bot.
Step 4: Set up a project in Amazon Pinpoint
Now we will create a new Pinpoint project that can send and receive SMS messages. To be able to receive incoming SMS messages, you also need to obtain a dedicated phone number.
To create a new SMS project
- Sign in to Amazon Pinpoint console.
- Create a new Pinpoint project name SAPSMS, and enable the SMS channel for the project. For more information, see Pinpoint documentation.
- Request a long code for your country. For more information, see
- Note: The procedures in the preceding link apply only to the United States and Canada. To request dedicated long codes for the SMS channel in other countries, see Pinpoint documentation.
- Enable the two-way SMS feature for the dedicated long code that you just purchased. Under Incoming message destination, choose Create a new SNS topic, and name it LexPinpointIntegrationDemo. For more information about setting up two-way SMS, see Pinpoint documentation.
Step 5: Set up the Lambda backend function to connect with Pinpoint
Now create a Lambda function to connect with pinpoint. This lambda function can be created by using step-3 of a blog Create an SMS Chatbot with Amazon Pinpoint and Lex and save this lambda as pinpoint-sap-integration. In the Designer section of this lambda function, choose Add trigger. Add a new SNS trigger, and then choose the LexPinpointIntegrationDemo topic that you created earlier in step-4
In the Environment variables section of this lambda, add the variables like BotName : sapbp, BotAlias : latest, PinpointApplicationId : The project id of the Pinpoint project and Region: The AWS Region of your Pinpoint project.
Step 6: Test the chatbot
Your SMS chatbot is now set up and ready to use! You can test it by sending a message (such as “Check Buyer Name”) to the long code that you obtained earlier. The chatbot responds, asking which sales order you want to check.
Clean up
You’ve now successfully integrated SAP with Amazon Pinpoint. To clean up your AWS account and to avoid ongoing charges for resources you created in this blog you should de-provision the following services that you set up:
Conclusion
Today, I’ve shown you how to configure an SMS-based chatbot to run queries into an SAP system. We’ve also explored how to integrate Amazon Pinpoint with SAP. This was a simple example of how to integrate SAP with AWS services like Amazon Pinpoint.
If you have questions or would like to know about SAP on AWS innovations, please visit aws.com/sap