Tag Archives: Alexa

Alexa, Add 2 Hosts to my SDDC

Recently I was doing labs for the AWS Developer Associate exam when it occurred to me that some time ago, I read a VMware blog about using Amazon Alexa to invoke VMware Cloud Application Programming Interfaces (APIs). The post was Amazon Alexa and VMware Cloud on AWS by Gilles Chekroun, and I decided to give it a go. First up, credit to Gilles for all the code, and the process outlined below. The Alexa Developer Console has improved over the last couple of years, and therefore I have included some updated screenshots and tweaks. Finally, this is just a bit of fun!

AlexaExample

Let’s take a look at some of the service involved:

AWS Lambda is a highly scalable serverless compute service, enabling customers to run application code on-demand without having to worry about any of the underlying infrastructure. Lambda supports multiple programming languages and uses functions to execute your code upon specific triggers. Event Sources are supported AWS services, or partner services used to trigger your Lambda functions with an operational event. You only pay for the compute power required when the function or code is running, which provides a cost-optimised solution for serverless environments.

Alexa, named after the Great Library of Alexandria, is Amazon’s Artificial Intelligence (AI) based virtual assistant allowing users to make voice initiated requests or ask questions. Alexa works with echo devices to listen for a wake word, using deep learning technology running on the device, which starts the Alexa Voice Service. The Alexa Voice Service selects the correct Alexa Skill based on user intent. Intents are words, or phrases, users say to interact with skills. Skills can be used to send POST requests to Lambda endpoints, or HTTPS web service endpoints, performing logic and returning a response in JSON format. The JSON is converted to an output which is then relayed back via the echo device using text to speech synthesis. You can read more about using Alexa to invoke Lambda functions at Host a Custom Skill as an AWS Lambda Function from the Alexa Skills Kit documentation.

VMware Cloud API Access

VMware Cloud APIs can be accessed at https://vmc.vmware.com/swagger/index.html#/, you need to be authenticated with a vmc.vmware.com account.

VMCAPIs

To use the VMware Cloud APIs, first generate an API token from the Cloud Provider Hub, under My Account, API Tokens.

APIToken

Once an API token has been generated, it can be exchanged for an authentication token, or access token, by using a REST client to POST to:

https://console.cloud.vmware.com/cphub/api/auth/v1/authn/accesstoken

The body content type should be application/JSON, with {“refreshToken” : “your_generated_api_token“} included in the body of the request. A successful 200 message is returned, along with the access token. Further information can be found at Using VMware Cloud Provider Hub APIs from the VMware Cloud Provider Hub API Programming Guide, or the API Explorer 

Lambda Function & Alexa Skill

The opening step is to log into the Alexa Developer Console and create a new skill. There are built-in skills for some scenarios like smart home interaction. In this instance, I am creating a custom skill.

Alexa1

Next, I add my invocation name, which will be used to call the skill. I then import Gilles’ JSON file to populate the intents, which gives me the basis of some of the Software-Defined Data Centre (SDDC) commands, I add some extra sample dialog.

Alexa2

In the Endpoint section, I take note of the Skill ID. The Skill ID will be used to invoke my Lambda function. Over in the AWS console, I open Lambda and create the function.

Lambda1

I defined the trigger as an Alexa Skills Kit, and enable Skill ID verification with the Skill ID copied in the previous step.

Lambda2

Since I have CloudTrail enabled, my API calls to Lambda will be forward to a CloudWatch Logs stream, which we’ll take a look at shortly. I also add a Simple Notification Service (SNS) topic to email me when the Lambda function is triggered.

Lambda4

Next, I upload Gilles’ code in zip format, making a couple of tweaks to the available region settings, and the org ID, SDDC ID, and API token. The code is actually going to go ahead and exchange that API token for me.

Lambda3

I run a simple test using a pre-configured test event from the Amazon Alexa Start Session event template. Then, make a note of the Amazon Resource Name (ARN) for the Lambda function in the top right corner.

Lambda5

Back in the Alexa Developer Console, I can now set this Lambda ARN as the service endpoint. I save and build my skill model.

Alexa3

In the Test section, I can use the invocation phrase defined by the Alexa Skill to start the demo, and my intents as words to trigger VMware Cloud API calls via Lambda. In the test below, I have added 2 additional hosts to my SDDC.

Alexa4

Back in the AWS console, from the CloudWatch Logs stream, I can see the API calls been made to Lambda.

CloudWatchLogs

In the VMware Cloud Provider Hub, the Adding host(s) task in progress message appears on the SDDC and the status changes to adding hosts. Following notification that the hosts were successfully added, I ask Alexa again what the SDDC status is, and the new capacity of 8 hosts is correctly reported back.