The following tools will enhance your developer experience.
- Have Node.JS on your laptop command-line, and become familiar with NPM, the Node Package Manager.
- Have GIT on your laptop.
- Have the AWS Command Line Interface (AWS CLI) installed and configured.
- Review the alexa-sdk documentation.
When creating a new AWS Lambda function, you can choose the alexa-skill-kit-sdk-factskill
blueprint which automatically bundles in the alexa-sdk. You can delete this code, and paste in sample code from this cookbook.
The online editor will work best if your skill code fits within a single file.
You may want to develop from a project folder on your local laptop for a number of reasons:
- You can create a project with more than one source file
- You can bundle in external Node.JS modules via NPM
- You can use your favorite text editor or IDE
- You can run unit tests locally
- You can upload your project to your personal GitHub repositoriy easily
You can download the entire Cookbook to your local hard drive in one of two ways:
- Click the green Clone or download button from the home page, and download the zip file. Be sure to extract everything to a new folder.
- If you have GIT installed, open a command prompt and run :
git clone https://github.com/alexa/Cookbook
You can also create a new skill function from scratch. Create an empty folder, and add a file called index.js
The examples each contain a /src
folder which contains the index.js
source file.
When the code runs within AWS Lambda, it relies on the alexa-sdk module, which is installed by default with the Fact skill blueprint.
In order to test and deploy projects from your local laptop, you will need to bundle in required modules such as the alexa-sdk within your /src
folder.
Follow these steps to install the alexa-sdk:
- Open a command prompt and navigate into the /src folder where your index.js lives.
- Verify you have Node.JS installed by typing
npm --version
- Type
npm install --save alexa-sdk
- You will notice a new folder called
node_modules
which contains analexa-sdk
folder. - You can repeat and use any other Node modules to your project with the npm command.
Note: You can install the aws-sdk
locally, however it is already available within Lambda and does not need to be bundled into your deployment.
You can now test your project from the command line, or package and deploy it to the AWS Lambda service.
Once you are ready to deploy your local code back into AWS Lambda, you can zip the contents of your /src
folder (just the contents, not the /src
parent folder) and publish the Zip archive to your Lambda function.
Manual steps:
- Within your file explorer tool, double-click into the /src folder
- Multi-select the index.js file, any other source files, the node_modules folder.
- Right-click and create a new zip file (zip, or send-to: compressed folder).
- Within the AWS Lambda console, create or locate the Lambda function.
- Within the Code section, locate the Code entry type dropdown.
- Click and select Upload a .ZIP file
- Locate and double click on the new zip file you made previously.
- You will need to click the blue "Save" button, or continue creating your new skill, for the upload to complete.
Automated steps:
-
You can choose to automate the packaging and publishing of your AWS Lambda project via a command line script. Read and follow the guide to Publishing Your Skill Code to Lambda via the Command Line Interface
-
Once the AWS CLI is setup, you can choose to use Node commands to deploy your function.
- Navigate to the
src/
folder and typenpm deploy
. This runs the commands defined in the scripts.deploy section of thesrc/package.json
file. You will need to customize thefunction-name
in a few places from the default of HelloWorld.
- Navigate to the
See also How To Test
Back to the Home Page