Use AWS Cloud9 or preffred IDE to execute the Lab session
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
cd ..
Login to your SAP Cloud Platform account. Check (this)[https://developers.sap.com/tutorials/cp-cf-download-cli.html)] for more information on which URL you should choose for logging in
Executee the below commands after getting your SCP app url.
cf login -a <YOUR SAP CLOUD PLATFORM URL for e.g. https://api.cf.us10.hana.ondemand.com>
To Create a connectivity service
cf create-service connectivity lite connectivity-lite -t alexademo_conn
To Create a destination service
cf create-service destination lite destination-lite -t alexademo_dest
To Create a XSUAA service
cf create-service xsuaa application odataproxy-uaa -c xs-security.json
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’
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
cf push
Once the application is deployed successfully. Log on the SAP Cloud Platform console using your web browswer, go to subaccounts -> spaces->[YOUR SPACE NAME].
Then go to Service Instances -> [Your XSUAA instance, for e.g. odataproxy-uaa] -> Show Sensitive data.
Note down the values for the following fields :
url
clientid
clientsecret
You will need to use them when you create an Alexa skill later.
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
cd aws-sap-alexa-scp/alexa/lambda
npm install
cd aws-sap-alexa-scp/alexa/lambda/lib
cd aws-sap-alexa-scp/alexa/lambda/lib/functions/aws-sap-alexa-scp-solo
npm install
npm i @aws-cdk/aws-ec2
cd aws-sap-alexa-scp/alexa/lambda/
cdk synth
cdk deploy
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’
Grant Type = Authorization Code
Callback URL = https://www.getpostman.com/oauth2/callback
Auth URL = + /oauth/authorize. For e.g. https://yourscpaccount.authentication.us10.hana.ondemand.com/oauth/authorize
Access Token URL = + /oauth/authorize. For e.g. https://yourscpaccount.authentication.us10.hana.ondemand.com/oauth/token
Client ID = ‘clientid’ from your XSUAA service in SAP Cloud Platform
Client Secret = ‘clientsecret’ from your XSUAA service in SAP Cloud Platform
Client Authentication = Send as Basic Auth Header
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’
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 wikipage 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.
Make sure you have activated ‘/sap/bc/soap/rfc’ for the ‘What is my user ID?’ question to work.
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
Thanks a lot for joining the workshop today! We hope you learned something and got inspired.