Published © GPL3+

Test Alexa Skills Offline (Python)

One of the most annoying parts of working on an Alexa skill is constantly having to upload deployment packages and have internet to work.

BeginnerProtip6 minutes2,493
Test Alexa Skills Offline (Python)

Things used in this project

Software apps and online services

Microsoft Visual Studio Code
As long as your IDE(s) support Python and JSON you are fine. Multi file is preferred.
Python
AWS Lambda
Amazon Web Services AWS Lambda
Alexa Skills Kit
Amazon Alexa Alexa Skills Kit

Story

Read more

Code

input.json

JSON
The input event for your function. Create it yourself or copy it from the testing pane in the developer portal.
{}

output.json

JSON
This is how the result should look if you change nothing.
{"status": "Complete", "value": "Value"}

test.py

Python
This script runs your function as if it is in Lambda.
import json
import lambda_function as program

with open('input.json') as data_file:    
    data = json.load(data_file)
    with open('output.json', 'w') as result_file:
        (json.dump(program.lambda_handler(data, {}), result_file))

lambda_function.py

Python
You should replace this with your own code.
import json
try:
    with open('vars.json') as data_file:    
        process = json.load(data_file)
except:
    print ("failed")
    pass

def lambda_handler(event, context):
    return {"status": 'Complete', "value": process['env']['name']}

vars.json

JSON
If using environment variables you must edit this file.
{"env": {"name": "Value"}}

Credits

Comments