Writing an Alexa skill using Ruby and AWS Lambda
2020-12-03
Previous article
What we’re doing
This post gets us started with AWS SAM and creates a demo hello world lambda function using Ruby.
Prerequisites
Follow the instructions listed in AWS SAM explaining how to
- Create an AWS account:
- Configure IAM permissions.
- Install Docker. Note: Docker is only a prerequisite for testing your application locally.
- Install Homebrew.
- Install the AWS SAM CLI.
At the end of this step, you should be able to successfully run
sam --version
at the command line and get back something like ‘SAM CLI, version 1.13.2’.
Creating a Hello world app
Follow the instructions in the tutorial to deploy a ‘hello world’ app to AWS (don’t forget to select Ruby), or follow here:
Start by
sam init
Enter the highlighted data as you’re prompted, selecting your own name for the app, of course:
At the end of this process, something like this would have been displayed:
Now run (substituting your app’s name):
cd lambda-alexa-myinfo
bundle
At this stage, the app is ready to be run locally, tested, or to be deployed.
Running locally
sam local start-api
will start a local instance at ‘localhost:3000’, and you can reach it by curl localhost:3000/hello-world
, you will get a 403 authentication error.
The better way to test this is to issue sam local invoke
that will create an image and run its container locally for testing:
Running tests
sam init
also created a test in tests/unit.
To run them using Rake, create a Rakefile at the root of the project and paste the following into it:
require 'rake/testtask'
task default: "test"
Rake::TestTask.new do |task|
task.pattern = 'tests/**/test_*.rb'
end
Save the file and issue rake
at the command line.
If the test fails, I think it’s because HTTParty is called with a failing expectation. I did not see the value in this and faked out the mock call to HTTParty. Comments welcome!
def test_lambda_handler
HTTParty.expects(:get).with('http://checkip.amazonaws.com/').returns(mock_response)
response = HTTParty.get('http://checkip.amazonaws.com/')
response.body
response.code
assert_equal(lambda_handler(event: event, context: ''), expected_result)
end
Deploying the app
Issue sam build
, and answer the questions as per your environment. Note that I am skipping the auth question:
Using the URL given to us at the end of the output, we can curl for the response:
curl https://<your path here>.execute-api.us-east-1.amazonaws.com/Prod/hello/
and visit that address using a browser.
What happened with my AWS account?
Once deployed, these will be the visible changes to your account:
- A new S3 bucket was created to hold the source code and template.
- A lambda function was created and registered.
- An API Gateway was created to route requests to the function.
- CloudFormation stacks
What’s next?
Wire up functions to handle Alexa requests
Previous article
Filed under
AWS
- Programming ESP32 using MQTT with AWS and FreeRTOS
- Quick AWS IoT Setup and test
- Set up AWS API GW with a Typescript authorizer and logging
- Use AWS CodePipline to execute CloudFormation templates
- Use GitHub Actions to deploy your SPA hosted on Amazon S3
- Use an AWS CloudFormation script to create and host an SPA on S3 with SSL and apex/subdomain redirection using CloudFront
Alexa
CloudFormation
How-to
Lambda
Ruby
Other Tags
API GW
AWS
- Programming ESP32 using MQTT with AWS and FreeRTOS
- Quick AWS IoT Setup and test
- Set up AWS API GW with a Typescript authorizer and logging
- Use AWS CodePipline to execute CloudFormation templates
- Use GitHub Actions to deploy your SPA hosted on Amazon S3
- Use an AWS CloudFormation script to create and host an SPA on S3 with SSL and apex/subdomain redirection using CloudFront
- Writing an Alexa skill using Ruby and AWS Lambda (Part 0)
ActiveRecord
Agile
- A review of software development metrics
- Agile programme management brief
- An alternative to current product development metrics
- An alternative to the current product development governance model
- Command & Control Management - The Party Killer
- Document Driven Development
- Inceptions revisited
- Managing multiple stakeholders
- Returns Driven Development
- The tip of the (good) iceberg
Alexa
Analysis
Ansible
BDD
BLE
C
CAB
CloudFormation
- Set up AWS API GW with a Typescript authorizer and logging
- Use AWS CodePipline to execute CloudFormation templates
- Use GitHub Actions to deploy your SPA hosted on Amazon S3
- Use an AWS CloudFormation script to create and host an SPA on S3 with SSL and apex/subdomain redirection using CloudFront
- Writing an Alexa skill using Ruby and AWS Lambda (Part 0)
CloudFront
CloudWatch
Cross-compile
Cucumber
DevOps
Devops
DotNet
Embedded
Fitbit
GNU
GitHub Actions
Governance
How-to
Inception
IoT
Javascript
Jest
Lambda
Mac OS X
- Bluetooth Low Energy (BLE) Implementing a peripheral on Mac OS X
- Cross-compiling for Raspberry Pi on a Mac and debugging using NetBeans
- Drobo will not mount in Finder
- Quickie - ssh dynamic port forwarding to avoid unsecured public networks
- Remote compilation, execution and debugging Raspberry Pi from a Mac using NetBeans
- Weekend warrior - MacRuby and rSpec, Mac OS X Lion, Xcode V4.3.2
MacRuby
Metrics
MySQL
NetBeans
Objective-C
PMO
Product Management
- A path to accelerating value realization
- A review of software development metrics
- Agile programme management brief
- An alternative to current product development metrics
- An alternative to the current product development governance model
- Express initiative kickoff formula
- Inceptions revisited
- Managing multiple stakeholders
- Plan for value delivery
- Pre-prod activity - Futurespective
- Value Stream Mapping
- When planning, it's not only about relative complexity
Programme management
Project Management
- A path to accelerating value realization
- A review of software development metrics
- Agile programme management brief
- An alternative to current product development metrics
- An alternative to the current product development governance model
- Command & Control Management - The Party Killer
- Express initiative kickoff formula
- Inceptions revisited
- Managing multiple stakeholders
- Plan for value delivery
- Pre-prod activity - Futurespective
- Value Stream Mapping
- When planning, it's not only about relative complexity
Quality Assurance
Rails
Raspberry Pi
Remote compilation
Remote debugging
Remote execution
Risk Assessment
Route 53
Ruby
- Alexa on Rails - how to develop and test Alexa skills using Rails
- Arduino programming using Ruby, Cucumber & rSpec
- How to reconnect to a database when its connection was lost
- Oh, the places you'll go...
- Quick AWS IoT Setup and test
- Weekend warrior - MacRuby and rSpec, Mac OS X Lion, Xcode V4.3.2
- Writing an Alexa skill using Ruby and AWS Lambda (Part 0)