Created by Chris Lennon using reveal.js
Source code available for both control code and the presentation
This presentation is to guide you through the creation of an application(skill) for the Alexa platform.
This presentation will give you an overview of (1) the Alexa platform, (2) the usage of a skill to control AWS as an example usecase.
This section is designed to give an overview of the Alexa ecosystem.
A non technical overview of components.
Builtin
Skill store
Build your own...
This section gives an overview of the components in a skill.
This section walks through the creation of a skill.
The example skill has the following requirements.
We need to install the AWS CLI and configure it.
aws iam get-user
{
"User": {
...
}
}
Naming things is hard...
Update ALEXA_SKILL_ID variable in serverless.yml
If using the example code you are good to go.
serverless deploy
But what did we actually deploy?...
A JSON payload following a particular format
{
...
"request": {
"type": "IntentRequest",
"intent": {
"name": "GetServices",
"slots": {
"Environment": {
"name": "Environment",
"value": "development"
}
}
}
}
...
}
... this bit is kind of up to you, example in a minute...
Actual speech is written in Speech Synthesis Markup Language (SSML)
I want to tell you a secret.
I am not a real human. .
Can you believe it?
A JSON payload following a particular format
{
...
"response": {
"outputSpeech": {
"type": "PlainText",
"text": "Plain text string to speak",
"ssml": "SSML text string to speak "
},
"card": {
"type": "Standard",
"title": "Title of the card",
"content": "Content of a simple card",
"text": "Text content for a standard card",
"image": {
"smallImageUrl": "https://url-to-small-card-image...",
"largeImageUrl": "https://url-to-large-card-image..."
}
},
"reprompt": {
"outputSpeech": {
"type": "PlainText",
"text": "Plain text string to speak",
"ssml": "SSML text string to speak "
}
}
}
...
}
But what about the middle part?
... What can I make it do?
Whatever you want!
My example ties uses Lambda to control AWS
Running the example
Creating: 'Alexa, list development servers'
Create a slot type
Setup the intent
Populate example phrases
Create a new blank function
The above is what serverless.yaml handles for us.
Two points to connect
Basic structure of function
def handler(event, context):
if (event["session"]["application"]["applicationId"] !=
os.environ.get('ALEXA_SKILL_ID')):
raise ValueError("Invalid Application ID")
if event["request"]["type"] == "LaunchRequest":
...
if event["request"]["type"] == "IntentRequest":
...
Assuming we are handling an IntentRequest
if event["request"]["intent"]["name"] == "GetServices"
return get_service_status(event["request"]["intent"]["slots"])
Pass the slot data to a function basaed on the intent name.
Query AWS using boto3 (built into Lambda)
ec2_resource = boto3.resource('ec2')
def get_service_status(slots):
filters = [{
'Name': name,
'Values': [slots['environment']['name']]
}]
instances = ec2_resource.instances.filter(Filters=filters)
for instance in instances:
if instance.state['Code'] == 16:
online_instances.append(instance.id)
else:
offline_instances.append(instance.id)
The previous function would need the AmazonEC2ReadOnlyAccess policy to be successful.
The goal is to respond with a SSML string.
{
...
"ssml" : "There are 2 development servers online. "
...
}
Considerations to grammar:
Many places to test!
serverless invoke local --function functionName -p test/data.json