<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andreas Jakl</title>
    <description>The latest articles on DEV Community by Andreas Jakl (@andijakl).</description>
    <link>https://dev.to/andijakl</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1139942%2Ff2a1b3b4-58f7-4946-854b-a0827f91c85a.jpeg</url>
      <title>DEV Community: Andreas Jakl</title>
      <link>https://dev.to/andijakl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/andijakl"/>
    <language>en</language>
    <item>
      <title>Local Debugging of Alexa Skills with Visual Studio Code</title>
      <dc:creator>Andreas Jakl</dc:creator>
      <pubDate>Wed, 16 Aug 2023 09:51:39 +0000</pubDate>
      <link>https://dev.to/aws-builders/local-debugging-of-alexa-skills-with-visual-studio-code-5g56</link>
      <guid>https://dev.to/aws-builders/local-debugging-of-alexa-skills-with-visual-studio-code-5g56</guid>
      <description>&lt;p&gt;Creating an Alexa-hosted skill is a fantastic way to start developing for voice assistants. However, you will eventually face issues that you need to debug in code. Alexa offers local skill debugging through Visual Studio Code but setting it up is a bit tricky. This guide will take you through the necessary steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Skill Environment
&lt;/h2&gt;

&lt;p&gt;This guide focuses on a Python-based skill and uses Windows as a local dev environment. Most also applies to other environments.&lt;/p&gt;

&lt;p&gt;I’ll start with a blank skill. First, create the skill in the Alexa Developer Console. The skill name I’m using in this example is &lt;em&gt;“local debugging test”&lt;/em&gt;. The &lt;em&gt;“type of experience”&lt;/em&gt; is &lt;em&gt;“Other”&lt;/em&gt;, with a &lt;em&gt;“Custom”&lt;/em&gt; model, as I’d like to start with a minimal blank skill. In the &lt;em&gt;“Hosting services”&lt;/em&gt; category, choose the &lt;em&gt;“Alexa-hosted (Python)”&lt;/em&gt; category. In the last step about templates, stick with &lt;em&gt;“Start from Scratch”&lt;/em&gt;, which will give you a minimal &lt;em&gt;Hello World&lt;/em&gt;-type voice interaction. The following screenshot summarizes the settings:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NU22b4jN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jei00zb2qfl55u35xcih.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NU22b4jN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jei00zb2qfl55u35xcih.png" alt="Review of the settings for the new Alexa skill that we will configure for local debugging through Visual Studio." width="800" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Other Prerequisites
&lt;/h3&gt;

&lt;p&gt;You should download and install &lt;a href="https://www.python.org/downloads/"&gt;Python&lt;/a&gt;, &lt;a href="https://gitforwindows.org/"&gt;Git for Windows&lt;/a&gt;, and &lt;a href="https://nodejs.org/en"&gt;Node.js&lt;/a&gt; (which is still useful for the go-to &lt;em&gt;Alexa Skills Kit Command Line Interface&lt;/em&gt; (ask-cli)). Make sure to restart Windows afterwards, as these tools need to integrate into your environment variables.&lt;/p&gt;

&lt;h2&gt;
  
  
  Downloading the Skill to Visual Studio Code
&lt;/h2&gt;

&lt;p&gt;Next, you download a local copy of the skill. Install the &lt;a href="https://marketplace.visualstudio.com/items?itemName=ask-toolkit.alexa-skills-kit-toolkit"&gt;Alexa Skills Toolkit for Visual Studio Code&lt;/a&gt; through the extensions manager.&lt;/p&gt;

&lt;p&gt;In the &lt;em&gt;Alexa Skills Toolkit&lt;/em&gt; tab in VS Code, in the &lt;em&gt;“Skills Management”&lt;/em&gt;-category, click on &lt;em&gt;“Download and edit skill”&lt;/em&gt;. After you signed into your Amazon Developer account, you will see the list of all your skills in the list. Select our new &lt;em&gt;“local debugging test”&lt;/em&gt; skill and choose any local folder to download the project content to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gqlnXnJ2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/od36vdz5hp4r708o9c5s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gqlnXnJ2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/od36vdz5hp4r708o9c5s.png" alt="Download the Alexa skill from the cloud to your local computer.&amp;lt;br&amp;gt;
" width="722" height="161"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should now see the skill downloaded with its individual sub-folders. To make saving configurations easier, save the VS Code workspace.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AQ1eE7pt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7vlnqqzob7u45vcls81.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AQ1eE7pt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7vlnqqzob7u45vcls81.png" alt="The “local debugging test” skill has been successfully downloaded to your local computer and is opened as a workspace in Visual Studio Code." width="429" height="323"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Working with Local and Remote Alexa Code
&lt;/h3&gt;

&lt;p&gt;Updating your Alexa-hosted skill through Visual Studio Code works through Git source control – but only half-way. Any code changes you make will be visible in the &lt;em&gt;“Source Control”&lt;/em&gt; tab. Commit any change you make there.&lt;/p&gt;

&lt;p&gt;This is also already necessary now, as a few files have been updated just by downloading the skill. Click the “Commit” button after adding a message; but don’t sync / push your changes to the remote origin manually.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eFE__BwP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pzp14bhn9m77z9aglye.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eFE__BwP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pzp14bhn9m77z9aglye.png" alt="Commit any changes you make to your skill through the “Source Control” tab of Visual Studio Code, but don’t sync manually." width="424" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead, go back to the &lt;em&gt;“Alexa Skills Toolkit”&lt;/em&gt; tab. In the &lt;em&gt;“Skills”&lt;/em&gt; category, choose &lt;em&gt;“Deploy skill”&lt;/em&gt;. All status checks should pass, and you can click the &lt;em&gt;“Deploy &amp;amp; build”&lt;/em&gt; button to sync your changes to the remote git and trigger a skill build on the Alexa backend. Don’t worry, this will take a few minutes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GRWk0OOC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yngng4rl0d4pp8m9o3vq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GRWk0OOC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yngng4rl0d4pp8m9o3vq.png" alt="Deploy and build your skill through the Alexa Skills Toolkit." width="800" height="551"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Local Debugging
&lt;/h2&gt;

&lt;p&gt;Now that you confirmed that the basic interaction of your local environment with the Alexa hosted skill environment works, it’s time to enable local debugging.&lt;/p&gt;

&lt;p&gt;Open a Terminal in Visual Studio Code. First, I’d recommend also setting up the global Alexa Skills Kit through &lt;code&gt;NPM&lt;/code&gt;, as this is easiest to use for some commands that are not available by the VS Code extension. Install and activate it through:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g ask-cli
ask configure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second command (&lt;code&gt;ask configure&lt;/code&gt;) will ask you to sign into your Amazon Developer Account. The login happens through the browser. You don’t need to link your AWS account for an Alexa hosted skill; it’s OK to skip that step. For more details, see the &lt;a href="https://github.com/alexa/ask-cli"&gt;ask-cli Github page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Next, we will configure the local debugger for the Python ASK SDK. The general description of the ASK SDK Local debug is available on &lt;a href="https://github.com/alexa/alexa-skills-kit-sdk-for-python/tree/master/ask-sdk-local-debug"&gt;Github&lt;/a&gt;. However, the description instructs you to use &lt;code&gt;virtualenv&lt;/code&gt;; according to the &lt;a href="https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment"&gt;Python documentation&lt;/a&gt;, you should use &lt;a href="https://packaging.python.org/en/latest/key_projects/#venv"&gt;venv&lt;/a&gt; for Python 3 (and &lt;a href="https://packaging.python.org/en/latest/key_projects/#virtualenv"&gt;virtualenv&lt;/a&gt; for Python 2). As we’re using Python 3 and &lt;code&gt;venv&lt;/code&gt; is pre-installed, it’s better to go with this variant. The adapted code for your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;py -m venv alexaenv
.\\alexaenv\\Scripts\\activate

pip install ask-sdk-core
pip install ask-sdk-local-debug

ask configure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What is happening here? We first create a virtual environment called &lt;code&gt;alexaenv&lt;/code&gt;. This will create a separate folder called &lt;code&gt;alexaenv&lt;/code&gt; in your project. You should later add this folder to your &lt;code&gt;gitignore&lt;/code&gt;, so that it doesn’t get checked in and remains local-only.&lt;/p&gt;

&lt;p&gt;Then, we use the command inside this environment to activate it. The following prompts will run inside your virtual environment. Even if you have already installed Python extensions outside, you will need to re-install them for your new environment. Therefore, we install both &lt;code&gt;ask-sdk-core&lt;/code&gt; as well as &lt;code&gt;ask-sdk-local-debug&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;At the end, you also need to configure this local Python version of &lt;em&gt;ASK&lt;/em&gt; to connect to your Amazon Developer account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eL7BZWlS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lbgaitrzupb88ybgzxgp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eL7BZWlS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lbgaitrzupb88ybgzxgp.png" alt="The first steps of creating the virtual environment for Python and installing &amp;amp; configuring the ASK (Alexa Skills Kit) tools for Python." width="704" height="161"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition, make sure that Visual Studio Code is also using your local Python environment to execute its commands. When you have a Python file open in the editor, look for the item in the lower right corner and switch to &lt;em&gt;“alexaenv (venv)”&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NfPFTpzM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d5f5rya4rz2qs8dtm8no.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NfPFTpzM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d5f5rya4rz2qs8dtm8no.png" alt="Switch to the new virtual environment Python installation in VS Code." width="380" height="88"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuring the Debugger in Visual Studio for Alexa Skills
&lt;/h3&gt;

&lt;p&gt;The official &lt;a href="https://developer.amazon.com/en-US/docs/alexa/ask-toolkit/vs-code-testing-simulator.html"&gt;Alexa developer documentation&lt;/a&gt; only contains examples for Node.js. However, there are a few small issues that are specific to the Python tools and Windows that you need to be aware of. Follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Open the Visual Studio Code &lt;em&gt;“Run”&lt;/em&gt; menu and choose &lt;em&gt;“Add Configuration…”&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt; In the &lt;em&gt;“Select debugger”&lt;/em&gt; box, click on &lt;em&gt;“Python”&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt; In the following choice, click on &lt;em&gt;“Python File”&lt;/em&gt;. This creates a run configuration file (&lt;code&gt;.vscode/launch.json&lt;/code&gt;). Note: We won’t use this config as we can’t directly run the main Python file from our skill code.&lt;/li&gt;
&lt;li&gt; Click on &lt;em&gt;“Add Configuration…”&lt;/em&gt; again. This time, the menu additionally contains the &lt;em&gt;“ASK: Alexa Skills Debugger (Python)”&lt;/em&gt; item. This adds a second configuration to our &lt;code&gt;launch.json&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt; The last item of &lt;em&gt;“args”&lt;/em&gt; is automatically selected, where you need to select your region. &lt;code&gt;NA&lt;/code&gt; is for North America, &lt;code&gt;EU&lt;/code&gt; for Europe, &lt;code&gt;FE&lt;/code&gt; for the Far East. This needs to correspond to your developer account region (not some skill setting!).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZuWHvdgd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sguot0lxs0u2ysuvob1j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZuWHvdgd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sguot0lxs0u2ysuvob1j.png" alt="Adding the correct debug configuration for the Alexa Skills Debugger (Python) in Visual Studio Code." width="800" height="612"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This should be it. After saving the file, you can switch to the &lt;em&gt;“Run and Debug”&lt;/em&gt; view in Visual Studio Code and choose the &lt;em&gt;“Debug Alexa Skill (Python)”&lt;/em&gt; configuration.&lt;/p&gt;

&lt;p&gt;Unfortunately, this fails with the error message &lt;em&gt;“Command failed: undefined”&lt;/em&gt;, which isn’t too helpful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KkFLN14G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7nv2824r3c06zaz0mr6o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KkFLN14G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7nv2824r3c06zaz0mr6o.png" alt="Error message when trying to launch local debugging of an Alexa Skill through the Python tools." width="469" height="158"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixing Issues with Local Debugging
&lt;/h2&gt;

&lt;p&gt;Searching for this error leads to an &lt;a href="https://github.com/alexa/ask-toolkit-for-vscode/issues/270"&gt;unresolved GitHub issue&lt;/a&gt; in the ASK Toolkit for Visual Studio Code in connection to the Python environment. At the time of writing, &lt;a href="https://github.com/caccia78"&gt;caccia78&lt;/a&gt; reported a workaround just a few days ago. Apparently, &lt;code&gt;command:ask.debugAdapterPath&lt;/code&gt; is not found, possibly due to a misconfiguration in the toolkit.&lt;/p&gt;

&lt;p&gt;The workaround is to list the absolute path. For the environment we created in this guide, it is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"program"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${workspaceFolder}/alexaenv/Lib/site-packages/ask&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s2"&gt;sdk&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s2"&gt;local&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s2"&gt;debug/local&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s2"&gt;debugger&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s2"&gt;invoker.py"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are two more issues you should correct. The auto-generated &lt;code&gt;launch.json&lt;/code&gt; file has a few comment lines (with &lt;code&gt;//&lt;/code&gt;) at the beginning. This kind of comment isn’t allowed in JSON format. Simply delete these lines. Additionally, Visual Studio Code highlights that &lt;code&gt;pythonPath&lt;/code&gt; isn’t allowed in a launch configuration, but it was added to the &lt;em&gt;“Debug Alexa Skill”&lt;/em&gt; configuration. It doesn’t hurt to remove that line as well. Your complete &lt;code&gt;launch.json&lt;/code&gt; file should look like the following at the end:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.2.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"configurations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Debug Alexa Skill (Python)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"request"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"launch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"program"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${workspaceFolder}/alexaenv/Lib/site-packages/ask&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s2"&gt;sdk&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s2"&gt;local&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s2"&gt;debug/local&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s2"&gt;debugger&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s2"&gt;invoker.py"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"args"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"--accessToken"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"${command:ask.accessToken}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"--skillId"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"${command:ask.skillIdFromWorkspace}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"--skillHandler"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"lambda&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s2"&gt;handler"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"--skillFilePath"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"${workspaceFolder}/lambda/lambda&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s2"&gt;function.py"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"--region"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"EU"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"console"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"internalConsole"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"cwd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${workspaceFolder}/lambda"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Python: Current File"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"request"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"launch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"program"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${file}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"console"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"integratedTerminal"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"justMyCode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Python Version &amp;amp; File Naming
&lt;/h3&gt;

&lt;p&gt;Another issue that depends on the installed environment is that some tool might have &lt;code&gt;python3&lt;/code&gt; hardcoded. However, the naming of the Python executable is platform-specific, which is also discussed in the &lt;a href="https://github.com/python/cpython/issues/99185"&gt;Python github issue tracker&lt;/a&gt;. On Linux and Mac, the executable is called &lt;code&gt;python3&lt;/code&gt;; on Windows, it’s just &lt;code&gt;python&lt;/code&gt; (unless you install it through the Windows Store – it’s complicated 🙄).&lt;/p&gt;

&lt;p&gt;Anyway, a simple workaround if you face this issue is to go to your &lt;code&gt;./alexaenv/Scripts/&lt;/code&gt; folder and create a copy of &lt;code&gt;python.exe&lt;/code&gt; that you then rename to &lt;code&gt;python3.exe&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Discovering Local Python Files / Modules
&lt;/h3&gt;

&lt;p&gt;As soon as your Python skill gets larger, you will want to split the code into multiple files. However, due to the way the skill is executed locally, you might get error messages like &lt;em&gt;“Failed to load the module”&lt;/em&gt; or &lt;em&gt;“ModuleNotFoundError: No module named xx”&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This happens even if you import your own &lt;code&gt;.py&lt;/code&gt; files correctly. For example, you can create a separate implementation file called &lt;code&gt;db_handler.py&lt;/code&gt; which contains a function &lt;code&gt;saveToDb&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;saveToDb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Saving to DB"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Saved to DB"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You then import this function into your main &lt;code&gt;lambda_function.py&lt;/code&gt; file through:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;\&lt;span class="n"&gt;_handler&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;saveToDb&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works fine when executed in the cloud; but not when debugging locally. You will get the following output in the &lt;em&gt;Debug Console&lt;/em&gt; window of Visual Studio Code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;File "C:\\Source\\Alexa\\localdebuggingtest/lambda/lambda\_function.py", line 20, in &amp;lt;module&amp;gt;
    from db\_handler import saveToDb
ModuleNotFoundError: No module named 'db\_handler'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://stackoverflow.com/a/70265733/1630203"&gt;StackOverflow user Luis Timaná provided a valid answer&lt;/a&gt; with a code example that solves the problem. The positive side is that the additional code doesn’t break executing your skill in the cloud. This means that you can simply add it before you do your first import of custom files. This is the code you need to add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;sys&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt;
&lt;span class="n"&gt;myDir&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getcwd&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;myDir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;
&lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;myDir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this fix, your code executes correctly on your local computer, and you will see the following output from the &lt;code&gt;print()&lt;/code&gt; statements in your &lt;em&gt;Debug Console&lt;/em&gt; window:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aKupzqlF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bq4n2fnczgob8a8pcr42.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aKupzqlF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bq4n2fnczgob8a8pcr42.png" alt="Output of print() statements in Python code in the debug console view of Visual Studio Code from the locally running Alexa skill." width="403" height="99"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Finally: Local Debugging of Alexa Skills in VS Code
&lt;/h2&gt;

&lt;p&gt;Once you’ve sorted out all the possible pitfalls and issues, you can finally start local debugging. In the &lt;em&gt;“Run and Debug”&lt;/em&gt; view of Visual Studio Code, click on the green run button with the &lt;em&gt;“Debug Alexa Skill (Python)”&lt;/em&gt; mode selected. A short while later, the debug controls appear on top of the file editor tabs. You can also set breakpoints in your code. A good first test is a breakpoint in the &lt;code&gt;handle()&lt;/code&gt; function of the &lt;code&gt;LaunchRequestHandler&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VRSqKnP---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ki18qi1bk6qgjdqt4xjt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VRSqKnP---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ki18qi1bk6qgjdqt4xjt.png" alt="A breakpoint in your locally running skill backend was hit and you can step through the code right from Visual Studio Code." width="800" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you start local debugging, the requests from the Alexa backend are routed to your local machine instead of the Lambda function in the cloud. This is active for one hour, unless you stop debugging earlier. This means that you can debug no matter which device you use: the Alexa simulator within VS Code, the Amazon Alexa Console Test-Tab or even a real Echo device.&lt;/p&gt;

&lt;p&gt;As soon as you launch your skill, it triggers your breakpoint. You can now step through the code and see all local variables.&lt;/p&gt;

&lt;p&gt;Note that depending on the test device, it might only wait for a few seconds for the response of your backend. This means that if you take longer to step through your code, the Amazon Echo device could give up waiting and stop. But that doesn’t prevent you from debugging in detail how your backend handles the relevant request with your breakpoint(s).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zZn4V9st--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uoqc726r82akeyrqo9wj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zZn4V9st--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uoqc726r82akeyrqo9wj.png" alt="The Alexa Skills Toolkit’s “Skill Simulation” running directly in Visual Studio Code." width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even though it is some work to set up, local debugging will save you a lot of time overall and is therefore worth it setting up right when you start developing your skill!&lt;/p&gt;

</description>
      <category>alexa</category>
      <category>tutorial</category>
      <category>aws</category>
      <category>vscode</category>
    </item>
  </channel>
</rss>
