Code Monkey home page Code Monkey logo

alexa-skill-with-sap-data-and-scp's Introduction

alexa-skill-with-sap-data-and-scp

This is a sample Alexa skill that integrates to a backend SAP application using SAP Cloud Platform and SAP Cloud Connector. This repository contains a sample SAP Cloud Platform (CloudFoundry) app that acts as an API endpoint to access backend SAP developer edition application through cloud connector. The backend SAP application and cloud connector can be in your on-premise or hosted on Amazon EC2 instances. SAP Cloud platform account can be in any region where CloudFoundry environment is supported.

Requirements

Setup Process

Note: This process creates various resources in your AWS account. Check the resources created section for more information on what gets created. You incur charges for using the resources created and you are responsible for those charges.

SAP Cloud Platform setup

  • Setup secure tunnel between ABAP System and SAP Cloud Platform through Cloud Connector - Set up Secure Tunnel between ABAP System and SAP Cloud Platform (CF) NOTE: In the tutorial above, under Step 3: Allow access to ABAP resources, use URL path as '/' instead of '/sap/opu/odata'. This will allow SCP to access all URL paths in the backend ABAP system

  • Configure SAP Cloud Connector for Principal propagation. Check How to Guide โ€“ Principal Propagation in an HTTPS Scenario blog for setup steps.

    NOTE:

    1. In the above blog, the author uses their SCP user ID to create a dummy user certificate in cloud connector for using in CERTRULE transaction. Since you will be using your SCP, I suggest you use your email ID that was used for the SCP account to generate the dummy certificate
    2. In CERTRULE transaction, the author is mapping the 'User Name' to the 'Login As' attribute. Here again, use email ID for 'Login As' attribute.
    3. Map the email ID to an available user ID in the SAP ABAP developer edition using SU01 transaction.
    4. The content under 'Create Destination' is outdated in this blog. Use the steps detailed below instead
  • Activate '/sap/bc/soap/rfc' in SICF transaction in SAP application

  • Create a destination with name 'sapgwdemo' for the ABAP virtual system in SAP Cloud Platform. See Managing Destinations for more more information on how to access the 'Create destination editor' and creating HTTP destinations using the destination editor.

SAP Cloud Platform deployment

  • Clone this repo to a folder of your choice

  • Navigate to the foloder that has the SAP Cloud Platform app and install dependecies

cd aws-sap-alexa-scp/sap-odata-proxy-api/odataproxyapi
npm install
  • Navigate one level up
cd ..
cf login -a <YOUR SAP CLOUD PLATFORM URL for e.g. https://api.cf.us10.hana.ondemand.com>
  • Create a connectivity service
cf create-service connectivity lite connectivity-lite -t alexademo_conn
  • Create a destination service
cf create-service destination lite destination-lite -t alexademo_dest
  • Create a XSUAA service
cf create-service xsuaa application odataproxy-uaa -c xs-security.json

NOTE:

  1. If you changed the name for connectivity, destination or XSUAA service about, then open the manifest.yml in a text editor and replace them as such under 'services'
  2. If you use a destination name is other than 'sapgwdemo' in the SAP Cloud Platform setup, then go to 'odataproxyapi' folder, open the start.js file and update the destination name for 'abapDest' constant.
const abapDest = '[replace this with your destination name if you used anything other than sapgwdemo]'

Similarly update the value for uaa, dest and conn variables under services.

  • Open the manifest.yml file and update the host field to something unique. For e.g. change it from awscf-odataproxy-api to -odataproxy-api. Otherwise, the deployment of the app could fail

  • Push the app to SAP Cloud Platform

cf push
  • Once the application is deployed successfully
    1. Log on the SAP Cloud Platform console using your web browswer, go to subaccounts -> spaces->[YOUR SPACE NAME].
    2. Then go to Service Instances -> [Your XSUAA instance, for e.g. odataproxy-uaa] -> Show Sensitive data.
    3. Note down the values for the following fields :
      • url
      • clientid
      • clientsecret

You will need to use them when you create an Alexa skill later.

Alexa skill deployment

  • Log on to your Alexa developer account and create a custom skill from scratch. Check Quick Reference: Create a custom skill for Alexa for more information on how to create a custom skill

  • Once inside the skill build console, go to the 'JSON Editor' in the left navigation and upload (or drag and drop) the skills.json file from the 'alexa' folder in this project.

  • The skills.json uses 'solo' as the invocation name. If want to use a different invocation name, update the value for 'invocationName' variable in the skills.json file.

  • Go to 'Endpoint' in the left navigation and choose 'AWS Lambda ARN' as the 'Service Endpoint Type'. Copy the 'Your Skill ID' to clipboard

  • Go to 'Account Linking' in the left navigation, enable 'Do you allow users to create an account or link to an existing account with you?'

  • Choose 'Auth Code Grant' and update the following fields. Leave other values as-is

AWS Lambda deployment

  • Navigate to the alexa/lambda/ folder and install dependencies
cd aws-sap-alexa-scp/alexa/lambda
npm install
  • Navigate to the alexa/lambda/lib folder
cd aws-sap-alexa-scp/alexa/lambda/lib
  • Open appConfig.json and update the following fields

    • account = [Your AWS Account ID]
    • region = [Your AWS region where you want the Lambda function to be deployed]
    • odataProxyAPIUrl = [Your odataproxyapi url from SAP cloud platform]. You can get this url by navigating to subaccount -> spaces -> [Your space] -> Applications -> odataproxyapi -> Application Routes. For e.g. https://mycf-odataproxy-api.cfapps.us10.hana.ondemand.com
    • alexaskill.name = [Your Alexa skill name. For e.g. solo]
    • alexaskill.id = [Your Alexa skill ID copied earlier from Alexa developer console. For e.g. amzn1.ask.skill.96d02cbf-ffda-4567-3454a-58222c9f9b50]
  • Navitage to alexa/lambda/lib/functions/aws-sap-alexa-scp-solo folder and install dependencies

cd aws-sap-alexa-scp/alexa/lambda/lib/functions/aws-sap-alexa-scp-solo
npm install
  • Navigate back to the lambda directory and deploy the resources to your AWS account. Make sure you AWS CLI is setup for accessing the correct AWS account
cd aws-sap-alexa-scp/alexa/lambda/
cdk synth
cdk deploy
  • Once the resources are successfully deployed, note down the Lambda ARN from the output. It is available as 'AlexaSkillLambdaFunctionArn' output field in cloud formation

Alexa Skill Build

  • Go back to your Alexa skill in the Alexa developer console, navigate to 'Endpoint' and update the Lambda ARN from above under 'Default Region' field.

  • Navigate to 'Invocation', 'Save Mode' and then 'Build Model'

Testing

  • First, test if you are able to able to access the SAP Cloud Platform service using a tool like Postman. For Authentication/Authorization, you can use 'OAuth2.0' type and get an access token. You can use the following fields to generate token

  • Once you have the token, send a 'GET' call to your SAP Cloud Platform app end point. You can get your end point url by navigating to subaccount -> spaces -> [Your space] -> Applications -> odataproxyapi -> Application Routes. For e.g. https://mycf-odataproxy-api.cfapps.us10.hana.ondemand.com. With this end point URL, you will be calling a backend OData service. If you are using ABAP developer edition, the url path can be /sap/opu/odata/IWBEP/GWSAMPLE_BASIC/BusinessPartnerSet?$format=json. So, the full URL for the postman get request will be something like this - https://mycf-odataproxy-api.cfapps.us10.hana.ondemand.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/BusinessPartnerSet?$format=json

  • If all works fine, you should get back list of busienss partners as JSON document as response

  • Now, test you Alexa skill. Launch https://alexa.amazon.com/ and log in using your Alexa developer account. Then navigate to Skills -> Your Skills -> Dev Skills -> [Your Skill Name; for e.g. solo] -> Enable Skill

  • Once skill is enabled, click on Settings -> Link Account -> Log in to SAP Cloud Platform account. This step will link your SAP Cloud Platform account with Alexa skill

  • Now, go back to Alexa developer console and test the skill by typing the following commands in the 'Alexa Simulator'

    • Launch solo (or whatever invocation name you used for your skill)
    • What is my user ID? (the response should display your SAP user ID if the SSO worked correctly)

Error Handling

  • Check the Lambda logs in case of skill response issues.

  • Check SAP Cloud platform application logs if the lambda is failing with an error response from SAP Cloud Platform

  • If you are hitting authorization errors, check if you client ID and secret is correct. If those are correct, increase the tracelevel in SMICM transaction in backend SAP and check if the SSO was successful. Check this wiki page on how to trouble shoot Cloud connector principal propagation over HTTPs

  • Make sure you have activated '/sap/bc/soap/rfc' for the 'What is my user ID?' question to work.

Created Resources by CDK/CloudFormation

  • Lambda function for handling Skill request/response and integrating with SAP Cloud Platform
  • A new role for Lambda execution
  • A new Lambda permission for the Alexa Skill

Cleanup

  • Delete all the AWS resources created
cd aws-sap-alexa-scp/alexa/lambda/
cdk destroy
  • Log on to SAP Cloud Platform and 'stop' the applications if required or delete them

  • Delete the Alexa skill if required

License

This project is licensed under the Apache-2.0 License.

alexa-skill-with-sap-data-and-scp's People

Contributors

amazon-auto avatar dependabot[bot] avatar kumarrk21 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

rjagirdaraw

alexa-skill-with-sap-data-and-scp's Issues

Could I try first the demo using a destination with basic authentication

Hi @kumarrk21 .

I'm trying to implement this but I have 2 questions,

  1. If I try to run the cf application from a browser it's normal that I have an Unauthorized error?
  2. I have implemented everything but not the principal propagation, for now I have basic authentication in the destination in cloud platform and I'm trying to test it but no success from alexa either from postman. I'm having the same response issue in the api url call (see below), since I have read your code you handle everything inside the router application as if it was principal propagation, may be that's why my scenario doesn't work, am I wrong?:
<title>Logon Error Message</title> <style type="text/css"> body { font-family: tahoma, helvetica, sans-serif; color: #333333; background-color: #FFFFFF; }
	td {
		font-family: tahoma, helvetica, sans-serif;
		font-size: 70%;
		color: #333333;
	}

	h1 {
		font-family: tahoma, helvetica, sans-serif;
		font-size: 160%;
		font-weight: bold;
		margin-top: 15px;
		margin-bottom: 3px;
		color: #003366;
	}

	h2 {
		font-family: verdana, helvetica, sans-serif;
		font-size: 120%;
		font-style: italic;
		font-weight: bold;
		margin-top: 6px;
		margin-bottom: 6px;
		color: #999900;
	}

	p {
		font-family: tahoma, helvetica, sans-serif;
		color: #333333;
		margin-top: 4px;
		margin-bottom: 4px;
	}

	ul {
		font-family: tahoma, helvetica, sans-serif;
		color: #333333;
		list-style-type: square;
		margin-top: 8px;
		margin-bottom: 8px;
	}

	li {
		font-family: tahoma, helvetica, sans-serif;
		color: #33333;
		margin-top: 4px;
	}

	.emphasize {
		color: #333333;
		background-color: #C8E3FF;
		padding: 5px;
	}

	.note {
		color: #CC6600;
	}

	a {
		font-family: tahoma, helvetica, sans-serif;
		text-decoration: underline;
		color: #336699;
	}

	a:visited {
		color: #001166;
	}

	a:hover {
		text-decoration: none;
	}
</style>

Anmeldung fehlgeschlagen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.