AX5: SCP Alexa deployment

Step 1: Clone the sample repo for SAP Cloud Platform deployment.

Use AWS Cloud9 or preffred IDE to execute the Lab session

  1. Clone this repo to a folder of your choice

  2. 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

  1. Navigate one level up

cd ..

  1. 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

  2. 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

NOTE:

  • 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

  1. Push the app to SAP Cloud Platform

cf push

  1. Once the application is deployed successfully. 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.

Note down the values for the following fields :

url
clientid
clientsecret

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

Step 2: Alexa skill deployment

  1. 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

  2. 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.

  3. 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.

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

  5. 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?’

  6. Choose ‘Auth Code Grant’ and update the following fields. Leave other values as-is

Step 3: AWS Lambda deployment

  1. Navigate to the alexa/lambda/ folder and install dependencies

cd aws-sap-alexa-scp/alexa/lambda
npm install

  1. Navigate to the alexa/lambda/lib folder
cd aws-sap-alexa-scp/alexa/lambda/lib

  1. 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]
  1. 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

npm i @aws-cdk/aws-ec2

  1. 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

  1. 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’

Step 4: Testing

  1. 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
  1. 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

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

  3. 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

  4. 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

  5. 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 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.

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

Step 5: Cleanup

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

  2. Delete the Alexa skill if required

Thank you!

Thanks a lot for joining the workshop today! We hope you learned something and got inspired.