├── .ask
└── config
├── .github
└── PULL_REQUEST_TEMPLATE.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── NOTICE
├── README.md
├── hooks
├── post_new_hook.ps1
├── post_new_hook.sh
├── pre_deploy_hook.ps1
└── pre_deploy_hook.sh
├── instructions
├── 1-voice-user-interface.md
├── 2-lambda-function.md
├── 3-connect-vui-to-code.md
├── 4-testing.md
├── 5-next-steps.md
└── lambda-role.md
├── lambda
└── py
│ ├── hello_world.py
│ └── requirements.txt
├── models
└── en-US.json
└── skill.json
/.ask/config:
--------------------------------------------------------------------------------
1 | {
2 | "deploy_settings": {
3 | "default": {
4 | "skill_id": "",
5 | "resources": {
6 | "lambda": [
7 | {
8 | "functionName": "",
9 | "alexaUsage": [
10 | "custom/default"
11 | ],
12 | "runtime": "python3.6",
13 | "handler": "hello_world.handler"
14 | }
15 | ]
16 | },
17 | "was_cloned": false,
18 | "merge": {}
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | *Issue #, if available:*
2 |
3 | *Description of changes:*
4 |
5 |
6 | By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
7 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | ## Code of Conduct
2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
4 | opensource-codeofconduct@amazon.com with any additional questions or comments.
5 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing Guidelines
2 |
3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
4 | documentation, we greatly value feedback and contributions from our community.
5 |
6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
7 | information to effectively respond to your bug report or contribution.
8 |
9 |
10 | ## Reporting Bugs/Feature Requests
11 |
12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features.
13 |
14 | When filing an issue, please check [existing open](https://github.com/alexa-labs/skill-sample-python-helloworld-decorators/issues), or [recently closed](https://github.com/alexa-labs/skill-sample-python-helloworld-decorators/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
16 |
17 | * A reproducible test case or series of steps
18 | * The version of our code being used
19 | * Any modifications you've made relevant to the bug
20 | * Anything unusual about your environment or deployment
21 |
22 |
23 | ## Contributing via Pull Requests
24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
25 |
26 | 1. You are working against the latest source on the *master* branch.
27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
29 |
30 | To send us a pull request, please:
31 |
32 | 1. Fork the repository.
33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
34 | 3. Ensure local tests pass.
35 | 4. Commit to your fork using clear commit messages.
36 | 5. Send us a pull request, answering any default questions in the pull request interface.
37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
38 |
39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
41 |
42 |
43 | ## Finding contributions to work on
44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels ((enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/alexa-labs/skill-sample-python-helloworld-decorators/labels/help%20wanted) issues is a great place to start.
45 |
46 |
47 | ## Code of Conduct
48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
50 | opensource-codeofconduct@amazon.com with any additional questions or comments.
51 |
52 |
53 | ## Security issue notifications
54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
55 |
56 |
57 | ## Licensing
58 |
59 | See the [LICENSE](https://github.com/alexa-labs/skill-sample-python-helloworld-decorators/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
60 |
61 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes.
62 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Amazon Software License 1.0
2 |
3 | This Amazon Software License ("License") governs your use, reproduction, and
4 | distribution of the accompanying software as specified below.
5 |
6 | 1. Definitions
7 |
8 | "Licensor" means any person or entity that distributes its Work.
9 |
10 | "Software" means the original work of authorship made available under this
11 | License.
12 |
13 | "Work" means the Software and any additions to or derivative works of the
14 | Software that are made available under this License.
15 |
16 | The terms "reproduce," "reproduction," "derivative works," and
17 | "distribution" have the meaning as provided under U.S. copyright law;
18 | provided, however, that for the purposes of this License, derivative works
19 | shall not include works that remain separable from, or merely link (or bind
20 | by name) to the interfaces of, the Work.
21 |
22 | Works, including the Software, are "made available" under this License by
23 | including in or with the Work either (a) a copyright notice referencing the
24 | applicability of this License to the Work, or (b) a copy of this License.
25 |
26 | 2. License Grants
27 |
28 | 2.1 Copyright Grant. Subject to the terms and conditions of this License,
29 | each Licensor grants to you a perpetual, worldwide, non-exclusive,
30 | royalty-free, copyright license to reproduce, prepare derivative works of,
31 | publicly display, publicly perform, sublicense and distribute its Work and
32 | any resulting derivative works in any form.
33 |
34 | 2.2 Patent Grant. Subject to the terms and conditions of this License, each
35 | Licensor grants to you a perpetual, worldwide, non-exclusive, royalty-free
36 | patent license to make, have made, use, sell, offer for sale, import, and
37 | otherwise transfer its Work, in whole or in part. The foregoing license
38 | applies only to the patent claims licensable by Licensor that would be
39 | infringed by Licensor's Work (or portion thereof) individually and
40 | excluding any combinations with any other materials or technology.
41 |
42 | 3. Limitations
43 |
44 | 3.1 Redistribution. You may reproduce or distribute the Work only if
45 | (a) you do so under this License, (b) you include a complete copy of this
46 | License with your distribution, and (c) you retain without modification
47 | any copyright, patent, trademark, or attribution notices that are present
48 | in the Work.
49 |
50 | 3.2 Derivative Works. You may specify that additional or different terms
51 | apply to the use, reproduction, and distribution of your derivative works
52 | of the Work ("Your Terms") only if (a) Your Terms provide that the use
53 | limitation in Section 3.3 applies to your derivative works, and (b) you
54 | identify the specific derivative works that are subject to Your Terms.
55 | Notwithstanding Your Terms, this License (including the redistribution
56 | requirements in Section 3.1) will continue to apply to the Work itself.
57 |
58 | 3.3 Use Limitation. The Work and any derivative works thereof only may be
59 | used or intended for use with the web services, computing platforms or
60 | applications provided by Amazon.com, Inc. or its affiliates, including
61 | Amazon Web Services, Inc.
62 |
63 | 3.4 Patent Claims. If you bring or threaten to bring a patent claim against
64 | any Licensor (including any claim, cross-claim or counterclaim in a
65 | lawsuit) to enforce any patents that you allege are infringed by any Work,
66 | then your rights under this License from such Licensor (including the
67 | grants in Sections 2.1 and 2.2) will terminate immediately.
68 |
69 | 3.5 Trademarks. This License does not grant any rights to use any
70 | Licensor's or its affiliates' names, logos, or trademarks, except as
71 | necessary to reproduce the notices described in this License.
72 |
73 | 3.6 Termination. If you violate any term of this License, then your rights
74 | under this License (including the grants in Sections 2.1 and 2.2) will
75 | terminate immediately.
76 |
77 | 4. Disclaimer of Warranty.
78 |
79 | THE WORK IS PROVIDED "AS IS" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
80 | EITHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OR CONDITIONS OF
81 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE OR
82 | NON-INFRINGEMENT. YOU BEAR THE RISK OF UNDERTAKING ANY ACTIVITIES UNDER
83 | THIS LICENSE. SOME STATES' CONSUMER LAWS DO NOT ALLOW EXCLUSION OF AN
84 | IMPLIED WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO YOU.
85 |
86 | 5. Limitation of Liability.
87 |
88 | EXCEPT AS PROHIBITED BY APPLICABLE LAW, IN NO EVENT AND UNDER NO LEGAL
89 | THEORY, WHETHER IN TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE
90 | SHALL ANY LICENSOR BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY DIRECT,
91 | INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR
92 | RELATED TO THIS LICENSE, THE USE OR INABILITY TO USE THE WORK (INCLUDING
93 | BUT NOT LIMITED TO LOSS OF GOODWILL, BUSINESS INTERRUPTION, LOST PROFITS
94 | OR DATA, COMPUTER FAILURE OR MALFUNCTION, OR ANY OTHER COMM ERCIAL DAMAGES
95 | OR LOSSES), EVEN IF THE LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF
96 | SUCH DAMAGES.
97 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | Hello World using Decorators (Python)
2 | Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Build an Alexa Hello World Skill in ASK Python SDK (using Decorators)
2 | =========================================
3 |
4 | This tutorial will walk first-time Alexa skills developers through all the
5 | required steps involved in creating a skill using this hello world template,
6 | called ‘hello world’. This post assumes you have some familiarity with
7 | Python (or a similar programming language) and the Alexa Skills Kit.
8 |
9 |
10 |
11 | Concepts
12 | --------
13 |
14 | This simple sample has no external dependencies or session management,
15 | and shows the most basic example of how to create a Lambda function for
16 | handling Alexa Skill requests.
17 |
18 | Setup
19 | -----
20 |
21 | To run this example skill you need to do two things. The first is to
22 | deploy the example code in lambda, and the second is to configure the
23 | Alexa skill to use Lambda.
24 |
25 | [](./instructions/1-voice-user-interface.md)
26 |
27 | Skills can be built either by implementing ``AbstractRequestHandler`` classes
28 | or by using skill builder's ``request_handler`` decorator. More information
29 | on this can be checked in the [documentation](https://alexa-skills-kit-python-sdk.readthedocs.io/en/latest/REQUEST_PROCESSING.html#request-handlers).
30 |
31 | This sample skill shows how to use skill builder's ``request_handler`` decorator.
32 | The code for this implementation is under [lambda/py](lambda/py) folder.
33 |
34 | For the sample skill using the ``AbstractRequestHandler`` classes approach, check
35 | [skill-sample-python-helloworld-classes](https://github.com/alexa/skill-sample-python-helloworld-classes).
36 |
37 | Additional Resources
38 | --------------------
39 |
40 | ### Community
41 |
42 | - [Amazon Developer Forums](https://forums.developer.amazon.com/spaces/165/index.html) : Join the conversation!
43 | - [Hackster.io](https://www.hackster.io/amazon-alexa) - See what others are building with Alexa.
44 |
45 | ### Tutorials & Guides
46 |
47 | - [Voice Design Guide](https://developer.amazon.com/designing-for-voice/) -
48 | A great resource for learning conversational and voice user interface design.
49 |
50 | ### Documentation
51 |
52 | - [Official Alexa Skills Kit Python SDK](https://pypi.org/project/ask-sdk/)
53 | - [Official Alexa Skills Kit Python SDK Docs](https://alexa-skills-kit-python-sdk.readthedocs.io/en/latest/)
54 | - [Official Alexa Skills Kit Docs](https://developer.amazon.com/docs/ask-overviews/build-skills-with-the-alexa-skills-kit.html)
55 |
56 |
--------------------------------------------------------------------------------
/hooks/post_new_hook.ps1:
--------------------------------------------------------------------------------
1 | # Powershell script for ask-cli post-new hook for Python
2 | # Script Usage: post_new_hook.ps1
3 |
4 | # SKILL_NAME is the preformatted name passed from the CLI, after removing special characters.
5 | # DO_DEBUG is boolean value for debug logging
6 |
7 | # Run this script one level outside of the skill root folder
8 |
9 | # The script does the following:
10 | # - Create a '.venv' directory under folder
11 | # - Find if python3 is installed.
12 | # - If yes, try creating virtual environment using built-in venv
13 | # - If that fails, install virtualenv and create virtualenv
14 | # - If no, install virtualenv and create virtualenv
15 | # - If virtual environment is created, use container pip to install dependencies from ${SOURCE_DIR}/requirements.txt
16 | # - Provide message on activation script location and additional dependencies
17 |
18 | param(
19 | [string] $SKILL_NAME,
20 | [bool] $DO_DEBUG = $False
21 | )
22 |
23 | if ($DO_DEBUG) {
24 | Write-Output "###########################"
25 | Write-Output "###### post-new hook ######"
26 | Write-Output "###########################"
27 | }
28 |
29 | function create_env () {
30 | # Check for Python3 installation
31 | python -V | Select-String -Pattern "Python 3." 2>&1 | Out-Null
32 | if ($?) {
33 | python -m venv $ENV_LOC 2>&1 | Out-Null
34 | if ($?) {
35 | return $true
36 | }
37 | }
38 | return create_using_virtualenv
39 | }
40 |
41 | function create_using_virtualenv() {
42 | # Check for virtualenv installation or install
43 | python -m pip install virtualenv 2>&1 | Out-Null
44 | if ($?) {
45 | python -m virtualenv $ENV_LOC 2>&1 | Out-Null
46 | if ($?) {
47 | return $true
48 | }
49 | }
50 | if ($DO_DEBUG) {
51 | Write-Output "There was a problem installing virtualenv"
52 | }
53 | return $false
54 | }
55 |
56 | function install_dependencies($PARAM_SOURCE_DIR) {
57 | # Install dependencies at lambda/py/requirements.txt
58 | $PYTHON_PATH = $ENV_LOC + "\Scripts\python"
59 | $REQUIREMENTS_PATH = $SKILL_NAME + "\" + $PARAM_SOURCE_DIR + "\requirements.txt"
60 | $CMD = "$PYTHON_PATH -m pip -q install -r $REQUIREMENTS_PATH"
61 | return Invoke-Expression $CMD 2>&1 | Out-Null
62 | }
63 |
64 |
65 | $SKILL_ENV_NAME = "skill_env"
66 | $ENV_LOC = $SKILL_NAME + "\.venv\" + $SKILL_ENV_NAME
67 | if (create_env) {
68 | $SKILL_FILE_PATH = $SKILL_NAME + "\skill.json"
69 | $ALL_SOURCE_DIRS = Get-Content -Path $SKILL_FILE_PATH | select-string -Pattern "sourceDir" -CaseSensitive
70 | if ($DO_DEBUG) {
71 | Write-Output "Created $SKILL_ENV_NAME virtualenv at $ENV_LOC"
72 | Write-Output "###########################"
73 | Write-Output "Installing dependencies based on sourceDir"
74 | }
75 | Foreach ($SOURCE_DIR in $ALL_SOURCE_DIRS) {
76 | $FILTER_SOURCE_DIR = $SOURCE_DIR -replace "`"", "" -replace "\s", "" -replace ",","" -replace "sourceDir:", ""
77 | if (-Not (install_dependencies $FILTER_SOURCE_DIR)) {
78 | if ($DO_DEBUG) {
79 | Write-Output "Codebase ($FILTER_SOURCE_DIR) built successfully."
80 | }
81 | } else {
82 | if ($DO_DEBUG) {
83 | Write-Output "There was a problem installing dependencies for ($FILTER_SOURCE_DIR)."
84 | }
85 | exit 1
86 | }
87 | }
88 | if ($DO_DEBUG) {
89 | Write-Output "###########################"
90 | Write-Output "Activate the environment before installing any other dependencies by running 'source $ENV_LOC/bin/activate'"
91 | }
92 | exit 0
93 | } else {
94 | exit 1
95 | }
96 |
--------------------------------------------------------------------------------
/hooks/post_new_hook.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Shell script for ask-cli post-new hook for Python
3 | # Script Usage: post_new_hook.sh
4 |
5 | # SKILL_NAME is the preformatted name passed from the CLI, after removing special characters.
6 | # DO_DEBUG is boolean value for debug logging
7 |
8 | # Run this script one level outside of the skill root folder
9 |
10 | # The script does the following:
11 | # - Create a '.venv' directory under folder
12 | # - Find if python3 is installed.
13 | # - If yes, try creating virtual environment using built-in venv
14 | # - If that fails, install virtualenv and create virtualenv
15 | # - If no, install virtualenv and create virtualenv
16 | # - If virtual environment is created, use container pip to install dependencies from ${SOURCE_DIR}/requirements.txt
17 | # - Provide message on activation script location and additional dependencies
18 |
19 | create_env () {
20 | # Check for Python3 installation
21 | if command -v python3 &> /dev/null; then
22 | PYTHON=python3
23 | # Use Python3's venv script to create virtualenv.
24 | if $PYTHON -m venv "$ENV_LOC"; then
25 | echo "Using Python3's venv script"
26 | return 0
27 | else
28 | # No venv script present (< Py 3.3). Install using virtualenv
29 | create_using_virtualenv $PYTHON
30 | return $?
31 | fi
32 | else
33 | # Python2 environment. Install using virtualenv
34 | PYTHON=python
35 | create_using_virtualenv $PYTHON
36 | return $?
37 | fi
38 | return 1
39 | }
40 |
41 | create_using_virtualenv () {
42 | # Check for virtualenv installation or install
43 | if $1 -m pip install virtualenv; then
44 | echo "Using virtualenv library"
45 | # Try creating env
46 | if $1 -m virtualenv "$ENV_LOC"; then
47 | return 0
48 | else
49 | echo "There was a problem creating virtualenv"
50 | return 1
51 | fi
52 | else
53 | echo "There was a problem installing virtualenv"
54 | return 1
55 | fi
56 | }
57 |
58 | install_dependencies() {
59 | # Install dependencies at lambda/py/requirements.txt
60 | return $("$ENV_LOC"/bin/python -m pip -q install -r "$SKILL_DIR"/"$1"/requirements.txt)
61 | }
62 |
63 | SKILL_NAME=$1
64 | DO_DEBUG=${2:-false}
65 | SKILL_DIR=$SKILL_NAME
66 | SKILL_ENV_NAME="skill_env"
67 | ENV_LOC="$SKILL_DIR/.venv/$SKILL_ENV_NAME"
68 |
69 | if ! $DO_DEBUG ; then
70 | exec > /dev/null 2>&1
71 | fi
72 |
73 | echo "###########################"
74 | echo "###### post-new hook ######"
75 | echo "###########################"
76 | echo "Creating virtualenv for $SKILL_NAME"
77 | mkdir "$SKILL_NAME/.venv"
78 | if create_env; then
79 | echo "Created $SKILL_ENV_NAME virtualenv at $ENV_LOC"
80 | echo "###########################"
81 | echo "Installing dependencies based on sourceDir"
82 | grep "sourceDir" "$SKILL_NAME/skill.json" | cut -d: -f2 | sed 's/"//g' | sed 's/,//g' | while read -r SOURCE_DIR; do
83 | if install_dependencies $SOURCE_DIR; then
84 | echo "Codebase ($SOURCE_DIR) built successfully."
85 | else
86 | echo "There was a problem installing dependencies for ($SOURCE_DIR)."
87 | exit 1
88 | fi
89 | done
90 | echo "###########################"
91 | echo "Activate the environment before installing any other dependencies by running 'source $ENV_LOC/bin/activate'"
92 | exit 0
93 | else
94 | exit 1
95 | fi
96 |
--------------------------------------------------------------------------------
/hooks/pre_deploy_hook.ps1:
--------------------------------------------------------------------------------
1 | # Powershell script for ask-cli pre-deploy hook for Python
2 | # Script Usage: pre_deploy_hook.ps1
3 |
4 | # SKILL_NAME is the preformatted name passed from the CLI, after removing special characters.
5 | # DO_DEBUG is boolean value for debug logging
6 | # TARGET is the deploy TARGET provided to the CLI. (eg: all, skill, lambda etc.)
7 |
8 | # Run this script under the skill root folder
9 |
10 | # The script does the following:
11 | # - Create a temporary 'lambda_upload' directories under each SOURCE_DIR folder
12 | # - Copy the contents of '/SOURCE_DIR' folder into '/SOURCE_DIR/lambda_upload'
13 | # - Copy the contents of site packages in $VIRTUALENV created in /.venv/ folder
14 | # - Update the location of this 'lambda_upload' folder to skill.json for zip and upload
15 |
16 | param(
17 | [string] $SKILL_NAME,
18 | [bool] $DO_DEBUG = $False,
19 | [string] $TARGET = "all"
20 | )
21 |
22 | if ($DO_DEBUG) {
23 | Write-Output "###########################"
24 | Write-Output "##### pre-deploy hook #####"
25 | Write-Output "###########################"
26 | }
27 |
28 | if ($TARGET -eq "all" -Or $TARGET -eq "lambda") {
29 | $ALL_SOURCE_DIRS = Get-Content -Path "skill.json" | select-string -Pattern "sourceDir" -CaseSensitive
30 | Foreach ($SOURCE_DIR in $ALL_SOURCE_DIRS) {
31 | # Step 1: Decide source path and upload path
32 | $FILTER_SOURCE_DIR = $SOURCE_DIR -replace "`"", "" -replace "\s", "" -replace ",","" -replace "sourceDir:", ""
33 | if ($FILTER_SOURCE_DIR.endsWith("/lambda_upload")) {
34 | $UPLOAD_DIR_PATH = $FILTER_SOURCE_DIR
35 | $CODE_PATH = $FILTER_SOURCE_DIR.replace("/lambda_upload", "")
36 | } else {
37 | $UPLOAD_DIR_PATH = $FILTER_SOURCE_DIR + "/lambda_upload"
38 | $CODE_PATH = $FILTER_SOURCE_DIR
39 | }
40 | # Step 2: Create empty lambda_upload folder
41 | Remove-Item -Recurse -Force $UPLOAD_DIR_PATH -ErrorAction Ignore
42 | New-Item -Force $UPLOAD_DIR_PATH -ItemType "directory" 2>&1 | Out-Null
43 |
44 | # Step 3: Copy source code in sourceDir to lambda_upload
45 | $EXCLUDE_PATH = Resolve-Path -Path ((pwd).Path + "/" + $UPLOAD_DIR_PATH)
46 | robocopy $CODE_PATH $UPLOAD_DIR_PATH /s /e /ndl /XD $EXCLUDE_PATH 2>&1 | Out-Null
47 |
48 | # Step 4: Find virtual environment site packages, copy contents to lambda_upload
49 | $SITE = $(.venv\skill_env\Scripts\python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
50 | Copy-Item "$SITE\*" -Destination $UPLOAD_DIR_PATH -Recurse
51 |
52 | # Step 5: Update the "manifest.apis.custom.endpoint.sourceDir" value in skill.json if necessary
53 | if (!$FILTER_SOURCE_DIR.endsWith("/lambda_upload")) {
54 | $RAW_SOURCE_DIR_LINE = "`"sourceDir`": `"$FILTER_SOURCE_DIR`""
55 | $NEW_SOURCE_DIR_LINE = "`"sourceDir`": `"$UPLOAD_DIR_PATH`""
56 | (Get-Content "skill.json").replace($RAW_SOURCE_DIR_LINE, $NEW_SOURCE_DIR_LINE) | Set-Content "skill.json"
57 | }
58 | }
59 |
60 | if ($DO_DEBUG) {
61 | Write-Output "###########################"
62 | }
63 |
64 | exit 0
65 | }
66 |
--------------------------------------------------------------------------------
/hooks/pre_deploy_hook.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Shell script for ask-cli pre-deploy hook for Python
3 | # Script Usage: pre_deploy_hook.sh
4 |
5 | # SKILL_NAME is the preformatted name passed from the CLI, after removing special characters.
6 | # DO_DEBUG is boolean value for debug logging
7 | # TARGET is the deploy TARGET provided to the CLI. (eg: all, skill, lambda etc.)
8 |
9 | # Run this script under skill root folder
10 |
11 | # The script does the following:
12 | # - Create a temporary 'lambda_upload' directories under each SOURCE_DIR folder
13 | # - Copy the contents of '/SOURCE_DIR' folder into '/SOURCE_DIR/lambda_upload'
14 | # - Copy the contents of site packages in $VIRTUALENV created in /.venv/ folder
15 | # - Update the location of this 'lambda_upload' folder to skill.json for zip and upload
16 |
17 | SKILL_NAME=$1
18 | DO_DEBUG=${2:-false}
19 | TARGET=${3:-"all"}
20 | SKILL_ENV_NAME="skill_env"
21 |
22 | if ! $DO_DEBUG ; then
23 | exec > /dev/null 2>&1
24 | fi
25 |
26 | echo "###########################"
27 | echo "##### pre-deploy hook #####"
28 | echo "###########################"
29 |
30 |
31 | RET=0
32 | if [[ $TARGET == "all" || $TARGET == "lambda" ]]; then
33 | grep "sourceDir" ./skill.json | cut -d: -f2 | sed 's/"//g' | sed 's/,//g' | while read -r SOURCE_DIR; do
34 | # Step 1: Decide source path and upload path
35 | if [[ $SOURCE_DIR == */lambda_upload ]]; then
36 | ADJUSTED_SOURCE_DIR=${SOURCE_DIR%"/lambda_upload"}
37 | UPLOAD_DIR=$SOURCE_DIR
38 | else
39 | ADJUSTED_SOURCE_DIR=$SOURCE_DIR
40 | UPLOAD_DIR="$SOURCE_DIR/lambda_upload"
41 | fi
42 |
43 | # Step 2: Create empty lambda_upload folder
44 | echo "Checking for lambda_upload folder existence in sourceDir $ADJUSTED_SOURCE_DIR"
45 | rm -rf $UPLOAD_DIR
46 | mkdir $UPLOAD_DIR
47 |
48 | # Step 3: Copy source code in sourceDir to lambda_upload
49 | echo "Copying source code in $SKILL_NAME/$ADJUSTED_SOURCE_DIR folder to $SKILL_NAME/$UPLOAD_DIR"
50 | rsync -avzq --exclude '*lambda_upload' $ADJUSTED_SOURCE_DIR/* $UPLOAD_DIR
51 |
52 | # Step 4: Find virtual environment site packages, copy contents to lambda_upload
53 | echo "Copying dependencies installed in $SKILL_NAME/.venv/$SKILL_ENV_NAME to $SKILL_NAME/$UPLOAD_DIR"
54 | if [[ ! "$(ls -A .venv/$SKILL_ENV_NAME/bin/python)" ]]; then
55 | echo "Failed to get virtual env Python runtime"
56 | RET=1
57 | break;
58 | fi
59 |
60 | SITE=$(.venv/$SKILL_ENV_NAME/bin/python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')
61 | if [[ "$(ls -A $SITE/*)" ]]; then
62 | cp -r $SITE/* $UPLOAD_DIR
63 | else
64 | echo "Failed to get the SITE package path"
65 | RET=1
66 | break;
67 | fi
68 |
69 | # Step 5: Update the "manifest.apis.custom.endpoint.sourceDir" value in skill.json if necessary
70 | if ! [[ $SOURCE_DIR == */lambda_upload ]]; then
71 | echo "Updating sourceDir to point to lambda_upload folder in skill.json"
72 | RAW_SOURCE_DIR_LINE="\"sourceDir\": \"$SOURCE_DIR\""
73 | NEW_SOURCE_DIR_LINE="\"sourceDir\": \"$UPLOAD_DIR\""
74 | sed -in "s#$RAW_SOURCE_DIR_LINE#$NEW_SOURCE_DIR_LINE#g" ./skill.json
75 | fi
76 | done
77 | echo "###########################"
78 | fi
79 |
80 | exit $RET
81 |
--------------------------------------------------------------------------------
/instructions/1-voice-user-interface.md:
--------------------------------------------------------------------------------
1 | # Build an Alexa Hello World Skill in ASK Python SDK
2 |
3 |
4 | [](./1-voice-user-interface.md)[](./2-lambda-function.md)[](./3-connect-vui-to-code.md)[](./4-testing.md)[](./5-next-steps.md)
5 |
6 | ## Setting up Your Alexa Skill in the Developer Console
7 |
8 | 1. **Go to the [Alexa Developer Console](http://developer.amazon.com/alexa?&sc_category=Owned&sc_channel=RD&sc_campaign=Evangelism2018&sc_publisher=github&sc_content=Survey&sc_detail=quiz-game-python-V2_GUI-1&sc_funnel=Convert&sc_country=WW&sc_medium=Owned_RD_Evangelism2018_github_Survey_quiz-game-python-V2_GUI-1_Convert_WW_beginnersdevs&sc_segment=beginnersdevs). In the top-right corner of the screen, click the "Sign In" button.**
9 | (If you don't already have an account, you will be able to create a new one for free.)
10 |
11 | 1. Once you have signed in, select the **Developer Console** link and then **Alexa Skills Kit**.
12 |
13 | 1. From the **Alexa Developer Console** select the **Create Skill** button near the top-right of the list of your Alexa Skills.
14 |
15 | 1. Give your new skill a **Name**, for example, 'Greeter'. This is the name that will be shown in the Alexa Skills Store, and the name your users will refer to.
16 |
17 | 1. Select the Default Language. This tutorial will presume you have selected 'English (US)'.
18 |
19 | 1. Select the **Custom** model under the *'Choose a model to add to your skill'* section. Click the **Create Skill** button at the top right.
20 |
21 | 1. Choose **Start from scratch** from the *Choose a template* section and click the **Choose** button on the top right.
22 |
23 | 1. **Build the Interaction Model for your skill**
24 | 1. On the left hand navigation panel, select the **JSON Editor** tab under **Interaction Model**. In the textfield provided, replace any existing code with the code provided in the [Interaction Model](../models/en-US.json). Click **Save Model**.
25 | 2. If you want to change the skill invocation name, select the **Invocation** tab. Enter a **Skill Invocation Name**. This is the name that your users will need to say to start your skill. In this case, it's preconfigured to be 'united states quiz game'.
26 | 3. Click "Build Model".
27 |
28 | **Note:** You should notice that **Intents** and **Slot Types** will auto populate based on the JSON Interaction Model that you have now applied to your skill. Feel free to explore the changes here, to learn about **Intents**, **Slots**, and **Utterances** open our [technical documentation in a new tab](https://developer.amazon.com/docs/custom-skills/create-intents-utterances-and-slots.html?&sc_category=Owned&sc_channel=RD&sc_campaign=Evangelism2018&sc_publisher=github&sc_content=Survey&sc_detail=quiz-game-python-V2_GUI-1&sc_funnel=Convert&sc_country=WW&sc_medium=Owned_RD_Evangelism2018_github_Survey_quiz-game-python-V2_GUI-1_Convert_WW_beginnersdevs&sc_segment=beginnersdevs).
29 |
30 | 7. **Optional:** Select an intent by expanding the **Intents** from the left side navigation panel. Add some more sample utterances for your newly generated intents. Think of all the different ways that a user could request to make a specific intent happen. A few examples are provided. Be sure to click **Save Model** and **Build Model** after you're done making changes here.
31 |
32 | 8. If your interaction model builds successfully, proceed to the next step. If not, you should see an error. Try to resolve the errors. In our next step of this guide, we will be creating our Lambda function in the AWS developer console, but keep this browser tab open, because we will be returning here on [Page #3: Connect VUI to Code](./3-connect-vui-to-code.md).
33 |
34 | If you get an error from your interaction model, check through this list:
35 |
36 | * **Did you copy & paste the provided code correctly?**
37 | * **Did you accidentally add any characters to the Interaction Model?**
38 |
39 | [](./2-lambda-function.md)
40 |
--------------------------------------------------------------------------------
/instructions/2-lambda-function.md:
--------------------------------------------------------------------------------
1 | # Build an Alexa Hello World Skill in ASK Python SDK
2 |
3 |
4 | [](./1-voice-user-interface.md)[](./2-lambda-function.md)[](./3-connect-vui-to-code.md)[](./4-testing.md)[](./5-next-steps.md)
5 |
6 | ## Setting Up A Lambda Function Using Amazon Web Services
7 |
8 | In the [first step of this guide](1-voice-user-interface.md), we built the Voice User Interface (VUI) for our Alexa skill. On this page, we will be creating a Lambda function using [Amazon Web Services](http://aws.amazon.com). You can [read more about what a Lambda function is](http://aws.amazon.com/lambda), but for the purposes of this guide, what you need to know is that Lambda is where our code lives. When a user asks Alexa to use our skill, it is our Lambda function that interprets the appropriate interaction, and provides the conversation back to the user.
9 |
10 | 1. **Go to http://aws.amazon.com and sign in to the console.** If you don't already have an account, you will need to create one. [Check out this quick walkthrough for setting up a new AWS account](https://alexa.design/create-aws-account).
11 |
12 | [](https://console.aws.amazon.com/console/home)
13 |
14 | 2. **Choose "Services" at the top of the screen, and type "Lambda" in the search box.** You can also find it in the list of services. It is in the "Compute" section.
15 |
16 | [](https://console.aws.amazon.com/lambda/home)
17 |
18 | 3. **Check your AWS region.** Lambda only works with the Alexa Skills Kit in four regions: US East (N. Virginia), EU (Ireland), US West (Oregon) and Asia Pacific (Tokyo). Make sure you choose the region closest to your customers.
19 |
20 | 
21 |
22 | 4. **Click the "Create a Lambda function" button.** It should be near the top of your screen.
23 |
24 | 
25 |
26 | 5. **Click on "Author from scratch".** We will configure our Lambda function next.
27 | 1. These values will only ever be visible to you, but make sure that you name your function something meaningful. "samplePythonHelloWorld" is sufficient if you don't have another idea for a name.
28 |
29 | 2. From the "Runtime" dropdown select the python version your system supports. This tutorial and sample code works with either Python 2.7 or 3.6. To check the python version, try the following command in a terminal
30 | ```
31 | $ python --version
32 | Python 2.7.10
33 | ```
34 |
35 | 3. **Set up your Lambda function role.** If you haven't done this before, we have a [detailed walkthrough for setting up your first role for Lambda](https://github.com/alexa/alexa-cookbook/blob/master/guides/aws-security-and-setup/lambda-role.md). If you have done this before, you only need to select the **Existing role**.
36 |
37 | 4. Click **Create function**.
38 |
39 | 6. **Configure your trigger.** There are many different AWS services that can trigger a Lambda function, but for the purposes of this guide, we need to select "Alexa Skills Kit." from the left hand side.
40 |
41 | Once you have selected Alexa Skills Kit, scroll down and find the Skill ID verification section. Although you will want to paste your skill's ID in the Skill ID field, however for this tutorial, click Disable. Click the **Add** button in the lower right. Click the orange **Save** button in the top right corner.
42 |
43 | 7. **Finish configuring your function**. Click on your function's name (you'll find it in the middle) and scroll to the bottom of the page, you'll see a Cloud9 code editor.
44 |
45 | We have provided the code for this skill on [here](../lambda/py). To properly upload this code to Lambda, you'll need to perform the following:
46 |
47 | 1. This skill uses the [ASK SDK for Python](https://github.com/alexa/alexa-skills-kit-sdk-for-python) for development. The skill code is provided in the [hello_world.py](../lambda/py/hello_world.py), and the dependencies are mentioned in [requirements.txt](../lambda/py/requirements.txt). Download the contents of the [lambda/py](../lambda/py) folder.
48 | 2. On your system, navigate to the lambda folder and install the dependencies in a new folder called “skill_env” using the following command:
49 |
50 | ```
51 | pip install -r py/requirements.txt -t skill_env
52 | ```
53 |
54 | 3. Copy the contents of the `lambda/py` folder into the `skill_env` folder.
55 |
56 | ```
57 | cp -r py/* skill_env/
58 | ```
59 |
60 | 4. Zip the contents of the `skill_env` folder. Remember to zip the **contents** of the folder and **NOT** the folder itself.
61 | 5. On the AWS Lambda console, change the **code entry type** drop-down to **Upload a .ZIP file**, upload the zip created in the previous step.
62 | 6. Change the handler name to ``hello_world.handler`` and click on **Save**.
63 |
64 | *(Optional)* Follow the ASK Python SDK [Getting Started](https://alexa-skills-kit-python-sdk.readthedocs.io/en/latest/GETTING_STARTED.html#adding-the-ask-sdk-for-python-to-your-project) documentation, to check alternative ways of installing the sdk and deploying to AWS Lambda console.
65 |
66 | 8. (Optional) Click the **Configure test events** dropdown menu on the top of the page.
67 |
68 | 1. Select 'Alexa Start Session' from the 'Event Template' dropdown.
69 | 2. Type `LaunchRequest` into the 'Event Name' field.
70 | 3. Click the orange 'Create' button at the bottom of the page
71 | 4. Click the **Test** button at the top of the page.
72 | 5. You should see a light green box with the message: *Execution result: succeeded* at the top of the page.
73 |
74 | 9. **As a final step, copy the ARN value from the top right corner of the screen.** You will need this value in the next section of this guide.
75 |
76 | [](3-connect-vui-to-code.md)
77 |
--------------------------------------------------------------------------------
/instructions/3-connect-vui-to-code.md:
--------------------------------------------------------------------------------
1 | # Build An Alexa Hello World Skill in ASK Python SDK
2 |
3 |
4 | [](./1-voice-user-interface.md)[](./2-lambda-function.md)[](./3-connect-vui-to-code.md)[](./4-testing.md)[](./5-next-steps.md)
5 |
6 | ## Connecting Your Voice User Interface To Your Lambda Function
7 |
8 | On [page #1](./1-voice-user-interface.md) of this guide, we created a voice user interface for the intents and utterances we expect from our users. On [page #2](./2-lambda-function.md), we created a Lambda function that contains all of our logic for the skill. On this page, we need to connect those two pieces together.
9 |
10 | 1. **Go back to the [Amazon Developer Portal](https://developer.amazon.com/edw/home.html#/skills/list) and select your skill from the list.** You may still have a browser tab open if you started at the beginning of this tutorial.
11 |
12 | 2. Select the **Endpoint** tab on the left side navigation panel.
13 |
14 | 3. **Select the "AWS Lambda ARN" option for your endpoint.** You have the ability to host your code anywhere that you would like, but for the purposes of simplicity and frugality, we are using AWS Lambda. ([Read more about Hosting Your Own Custom Skill Web Service](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/developing-an-alexa-skill-as-a-web-service).) With the AWS Free Tier, you get 1,000,000 free requests per month, up to 3.2 million seconds of compute time per month. Learn more at https://aws.amazon.com/free/. In addition, Amazon now offers [AWS Promotional Credits for developers who have live Alexa skills that incur costs on AWS related to those skills](https://developer.amazon.com/alexa-skills-kit/alexa-aws-credits).
15 |
16 | 4. Paste your Lambda's ARN (Amazon Resource Name) into the textbox provided for **Default Region**.
17 |
18 | 5. Click the **Save Endpoints** button at the top of the main panel.
19 |
20 | 6. **Click the "Next" button to continue to page #4 of this guide.**
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/instructions/4-testing.md:
--------------------------------------------------------------------------------
1 | # Build An Alexa Hello World Skill in ASK Python SDK
2 |
3 |
4 | [](./1-voice-user-interface.md)[](./2-lambda-function.md)[](./3-connect-vui-to-code.md)[](./4-testing.md)[](./5-next-steps.md)
5 |
6 | ## Testing Your Alexa Skill
7 |
8 | So far, we have [created a Voice User Interface](./1-voice-user-interface.md) and [a Lambda function](./2-lambda-function.md), and [connected the two together](./3-connect-vui-to-code.md). Your skill is now ready to test.
9 |
10 | 1. **Go back to the [Amazon Developer Portal](https://developer.amazon.com/edw/home.html#/skills/list) and select your skill from the list.** You may still have a browser tab open if you started at the beginning of this tutorial.
11 |
12 | 2. Open the **Test** Pane, by selecting the **Test** link from the top navigation menu.
13 |
14 | 3. Enable Testing by activating the **Test is enabled for this skill** slider. It should be underneath the top navigation menu.
15 |
16 | 4. To validate that your skill is working as expected, invoke your skill from the **Alexa Simulator**. You can either type or click and hold the mic from the input box to use your voice.
17 | 1. **Type** "Open" followed by the invocation name you gave your skill in [Step 1](./1-voice-user-interface.md). For example, "Open greeter".
18 | 2. **Use your voice** by clicking and holding the mic on the side panel and saying "Open" followed by the invocation name you gave your skill.
19 | 3. **If you've forgotten the invocation name** for your skill, revisit the **Build** panel on the top navigation menu and select Invocation from the sidebar to review it.
20 |
21 | 5. Ensure your skill works the way that you designed it to.
22 | * After you interact with the Alexa Simulator, you should see the Skill I/O **JSON Input** and **JSON Output** boxes get populated with JSON data. You can also view the **Device Log** to trace your steps.
23 | * If it's not working as expected, you can dig into the JSON to see exactly what Alexa is sending and receiving from the endpoint. If something is broken, AWS Lambda offers an additional testing tool to help you troubleshoot your skill.
24 |
25 | 6. **Configure a test event in AWS Lambda.** Now that you are familiar with the **request** and **response** boxes in the Service Simulator, it's important for you to know that you can use your **requests** to directly test your Lambda function every time you update it. To do this:
26 | 1. Enter an utterance in the service simulator, and copy the generated Lambda Request for the next step.
27 |
28 | 2. **Open your Lambda function in AWS, open the Actions menu, and select "Configure test events."**
29 |
30 |
31 |
32 | 3. **Select "Create New Test Event". Choose "Alexa Start Session" as the Event Template from the dropdown list.** You can choose any test event in the list, as they are just templated event requests, but using "Alexa Start Session" is an easy one to remember.
33 |
34 |
35 |
36 | 4. **Type in an Event Name into the Event Name Dialog box. Delete the contents of the code editor, and paste the Lambda request you copied above into the code editor.** The Event Name is only visible to you. Name your test event something descriptive and memorable. For our example, we entered an event name as "startSession". Additionally, by copying and pasting your Lambda Request from the service simulator, you can test different utterances and skill events beyond the pre-populated templates in Lambda.
37 |
38 |
39 |
40 | 5. **Click the "Create" button.** This will save your test event and bring you back to the main configuration for your lambda function.
41 |
42 | 6. **Click the "Test" button to execute the "startSession" test event.**
43 |
44 |
45 |
46 | This gives you visibility into four things:
47 |
48 | * **Your response, listed in the "Execution Result."**
49 |
50 |
51 |
52 | * **A Summary of the statistics for your request.** This includes things like duration, resources, and memory used.
53 |
54 |
55 |
56 | * **Log output.** By effectively using print() or python logger statements in your Lambda code, you can track what is happening inside your function, and help to figure out what is happening when something goes wrong. You will find the log to be incredibly valuable as you move into more advanced skills.
57 |
58 |
59 |
60 | * **A link to your [CloudWatch](https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs:) logs for this function.** This will show you **all** of the responses and log statements from every user interaction. This is very useful, especially when you are testing your skill from a device with your voice. (It is the "[Click here](https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs:)" link in the Log Output description.)
61 |
62 | 7. **Other testing methods to consider:**
63 |
64 | * [Echosim.io](https://echosim.io) - a browser-based Alexa skill testing tool that makes it easy to test your skills without carrying a physical device everywhere you go.
65 | * [Unit Testing with Alexa](https://github.com/alexa/alexa-cookbook/tree/master/testing/postman/README.md) - a modern approach to unit testing your Alexa skills with [Postman](http://getpostman.com) and [Amazon API Gateway](http://aws.amazon.com/apigateway).
66 |
67 | 8. **If your sample skill is working properly, you can now customize your skill.**
68 |
69 |
70 |
--------------------------------------------------------------------------------
/instructions/5-next-steps.md:
--------------------------------------------------------------------------------
1 | # Build An Alexa Hello World Skill in ASK Python SDK
2 |
3 |
4 | [](./1-voice-user-interface.md)[](./2-lambda-function.md)[](./3-connect-vui-to-code.md)[](./4-testing.md)[](./5-next-steps.md)
5 |
6 | ## Customization / Next Steps
7 |
8 | At this point, you should have a working copy of our Hello World skill.
9 |
10 | Normally, if you were building a skill from one of our templates, you would customize it and make it your own (as opposed to a clone of our template). After that, you would certify and publish the skill. Given that this is the Hello World skill, you won't be doing that. Instead, check out some of these other templates which will start to show you more of the features of the Alexa Skills Kit.
11 |
12 | * [Simple Facts Skill](https://github.com/alexa/skill-sample-python-fact) - A simple facts skill that can be used as a starter template.
13 | * [Color Picker Skill](https://github.com/alexa/skill-sample-python-colorpicker) - A simple color picker skill that shows how to use session attributes.
14 | * [High Low Game Skill](https://github.com/alexa/skill-sample-python-highlowgame) - the High Low Game skill is a simple example and a great next step after Hello World. The skill asks user to guess a number and tells if the guessed number is higher or lower than the correct guess.
15 | * [Quiz Skill](https://github.com/alexa/skill-sample-python-quiz-game) - a skill where the user can ask for information on one of the states of US and play a quiz around the states. This sample skill shows off the render template directive usage.
16 | * [Fact w/In Skill Purchasing](https://github.com/alexa/skill-sample-python-fact-in-skill-purchases) - takes the Fact skill and adds in skill purchasing to it.
17 | * [Pet Match Skill](https://github.com/alexa/skill-sample-python-pet-match) - a skill where the user is asked for their ideal requirements and matches with a dog. Shows off the dialog management and entity resolution.
18 | * [City Guide Skill](https://github.com/alexa/skill-sample-python-city-guide) - a skill that provides restaurant recommendations, attractions and current weather for a city. Shows off the external API call usage.
19 | * [How-To Skill](https://github.com/alexa/skill-sample-python-how-to) - a skill that provides how to obtain a random item. Shows off multiple locales and localization usage.
20 |
--------------------------------------------------------------------------------
/instructions/lambda-role.md:
--------------------------------------------------------------------------------
1 | # Setting Up Your First Lambda Role
2 |
3 | If you're reading this page, you're probably setting up your first role for a Lambda function. While it's an easy process, we want to make sure you understand all of the "whys" that go into this process.
4 |
5 | 1. **Choose "Create a custom role" from the Role dropdown.** This will launch a new tab in your browser, so make sure that popups are enabled when you attempt this.
6 |
7 | 
8 |
9 | 2. **You are now creating a new IAM role.** IAM stands for Identity and Access Management. ([You can read more about IAM here.](http://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)) By creating this role, you are enabling your Lambda function to be able to create Amazon CloudWatch logs for your function. ([You can read more about managing permissions with IAM roles here.](https://docs.aws.amazon.com/lambda/latest/dg/intro-permission-model.html#lambda-intro-execution-role))
10 |
11 | 3. **You don't need to make any changes. Click the Allow button in the bottom right corner.**
12 |
13 | 
14 |
15 | 4. **This should close the new tab, and populate your Lambda function appropriately.** If your "Lambda function handler and role" section doesn't look like the screenshot below, try refreshing your page and selecting your new role from the "existing role" dropdown.
16 |
17 | 
18 |
19 | 5. **You can now return to what you were doing.**
20 |
--------------------------------------------------------------------------------
/lambda/py/hello_world.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | # This is a simple Hello World Alexa Skill, built using
4 | # the decorators approach in skill builder.
5 | import logging
6 |
7 | from ask_sdk_core.skill_builder import SkillBuilder
8 | from ask_sdk_core.utils import is_request_type, is_intent_name
9 | from ask_sdk_core.handler_input import HandlerInput
10 |
11 | from ask_sdk_model.ui import SimpleCard
12 | from ask_sdk_model import Response
13 |
14 | sb = SkillBuilder()
15 |
16 | logger = logging.getLogger(__name__)
17 | logger.setLevel(logging.INFO)
18 |
19 |
20 | @sb.request_handler(can_handle_func=is_request_type("LaunchRequest"))
21 | def launch_request_handler(handler_input):
22 | """Handler for Skill Launch."""
23 | # type: (HandlerInput) -> Response
24 | speech_text = "Welcome to the Alexa Skills Kit, you can say hello!"
25 |
26 | return handler_input.response_builder.speak(speech_text).set_card(
27 | SimpleCard("Hello World", speech_text)).set_should_end_session(
28 | False).response
29 |
30 |
31 | @sb.request_handler(can_handle_func=is_intent_name("HelloWorldIntent"))
32 | def hello_world_intent_handler(handler_input):
33 | """Handler for Hello World Intent."""
34 | # type: (HandlerInput) -> Response
35 | speech_text = "Hello Python World from Decorators!"
36 |
37 | return handler_input.response_builder.speak(speech_text).set_card(
38 | SimpleCard("Hello World", speech_text)).set_should_end_session(
39 | True).response
40 |
41 |
42 | @sb.request_handler(can_handle_func=is_intent_name("AMAZON.HelpIntent"))
43 | def help_intent_handler(handler_input):
44 | """Handler for Help Intent."""
45 | # type: (HandlerInput) -> Response
46 | speech_text = "You can say hello to me!"
47 |
48 | return handler_input.response_builder.speak(speech_text).ask(
49 | speech_text).set_card(SimpleCard(
50 | "Hello World", speech_text)).response
51 |
52 |
53 | @sb.request_handler(
54 | can_handle_func=lambda handler_input:
55 | is_intent_name("AMAZON.CancelIntent")(handler_input) or
56 | is_intent_name("AMAZON.StopIntent")(handler_input))
57 | def cancel_and_stop_intent_handler(handler_input):
58 | """Single handler for Cancel and Stop Intent."""
59 | # type: (HandlerInput) -> Response
60 | speech_text = "Goodbye!"
61 |
62 | return handler_input.response_builder.speak(speech_text).set_card(
63 | SimpleCard("Hello World", speech_text)).response
64 |
65 |
66 | @sb.request_handler(can_handle_func=is_intent_name("AMAZON.FallbackIntent"))
67 | def fallback_handler(handler_input):
68 | """AMAZON.FallbackIntent is only available in en-US locale.
69 | This handler will not be triggered except in that locale,
70 | so it is safe to deploy on any locale.
71 | """
72 | # type: (HandlerInput) -> Response
73 | speech = (
74 | "The Hello World skill can't help you with that. "
75 | "You can say hello!!")
76 | reprompt = "You can say hello!!"
77 | handler_input.response_builder.speak(speech).ask(reprompt)
78 | return handler_input.response_builder.response
79 |
80 |
81 | @sb.request_handler(can_handle_func=is_request_type("SessionEndedRequest"))
82 | def session_ended_request_handler(handler_input):
83 | """Handler for Session End."""
84 | # type: (HandlerInput) -> Response
85 | return handler_input.response_builder.response
86 |
87 |
88 | @sb.exception_handler(can_handle_func=lambda i, e: True)
89 | def all_exception_handler(handler_input, exception):
90 | """Catch all exception handler, log exception and
91 | respond with custom message.
92 | """
93 | # type: (HandlerInput, Exception) -> Response
94 | logger.error(exception, exc_info=True)
95 |
96 | speech = "Sorry, there was some problem. Please try again!!"
97 | handler_input.response_builder.speak(speech).ask(speech)
98 |
99 | return handler_input.response_builder.response
100 |
101 |
102 | handler = sb.lambda_handler()
103 |
--------------------------------------------------------------------------------
/lambda/py/requirements.txt:
--------------------------------------------------------------------------------
1 | ask-sdk-core
2 |
--------------------------------------------------------------------------------
/models/en-US.json:
--------------------------------------------------------------------------------
1 | {
2 | "interactionModel": {
3 | "languageModel": {
4 | "invocationName": "greeter",
5 | "intents": [
6 | {
7 | "name": "AMAZON.FallbackIntent",
8 | "samples": []
9 | },
10 | {
11 | "name": "AMAZON.CancelIntent",
12 | "samples": []
13 | },
14 | {
15 | "name": "AMAZON.HelpIntent",
16 | "samples": []
17 | },
18 | {
19 | "name": "AMAZON.StopIntent",
20 | "samples": []
21 | },
22 | {
23 | "name": "HelloWorldIntent",
24 | "slots": [],
25 | "samples": [
26 | "how are you",
27 | "say hi world",
28 | "say hi",
29 | "hi",
30 | "hello",
31 | "say hello world",
32 | "say hello"
33 | ]
34 | }
35 | ],
36 | "types": []
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/skill.json:
--------------------------------------------------------------------------------
1 | {
2 | "manifest": {
3 | "publishingInformation": {
4 | "locales": {
5 | "en-US": {
6 | "summary": "Sample Short Description",
7 | "examplePhrases": [
8 | "Alexa open hello decorator world",
9 | "hello",
10 | "help"
11 | ],
12 | "name": "Hello Decorator World",
13 | "description": "Sample Full Description"
14 | }
15 | },
16 | "isAvailableWorldwide": true,
17 | "testingInstructions": "Sample Testing Instructions.",
18 | "distributionCountries": []
19 | },
20 | "apis": {
21 | "custom": {
22 | "endpoint": {
23 | "sourceDir": "lambda/py",
24 | "uri": "ask-custom-helloworld-decorators-default"
25 | }
26 | }
27 | },
28 | "manifestVersion": "1.0"
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------