Work Locally on Your Alexa Skill

Set Your Lambda Function Up and Deploy it From Your Machine

April 19, 2020

This is a follow-up post from Building an Alexa Skill to explain how simple it easy to work on your Lambda function locally instead of in the AWS console.

In my Building an Alexa Skill post, we created a simple Alexa skill together, created our Lambda function, and connected the 2 together. Right now, our Lambda function lives in the AWS console.

Lambda function in the AWS console.

Let's start by exporting our function. Click on the 'Actions' dropdown.

Export function.

Then select 'Download deployment package'.

Download deployment package'

Once your function has downloaded, feel free to move the directory to a location of your choice and rename. When it's how and where you'd like it to be, change into that directory from the terminal and install the dependencies using either npm or yarn.

Before we go through the simple steps of deploying our function, let's make a small change somewhere so that when we deploy our function soon, you can confirm the difference exists in the console.

Lambda function. Adding a comment.

The first thing we need to do is create a zip file that we'll deploy. From within your lambda function, you can do this easily by running: zip -r ../ . For me, when I run zip -r ../ . I see a really a really quick output of node_modules, the index.js file, package.json, and package-lock.json files and folders being added.

Zipping a lambda function.

There's no errors or warnings so I'm assuming everything worked out. To be sure, there's 2 things I can do:
  • run ls .. to make sure there's a zip file called '', and or
  • run unzip -l ../

If you run that second command with the name of your zip file, you should see something like the following which signifies the zip file was created successfully:

Confirming the zip worked.

The only thing that is left to do is deploy our function. In order for this to be possible you need to make sure you have the aws-cli installed on your machine and have your credentials set up locally. If you don't know how to do that, I recommend reading Setting Up Your AWS Credentials first and then coming back to wrap this up when you're done.

The command to deploy our lambda function is a pretty lengthy command that looks something like this:
aws lambda update-function-code --function-name serverlessrepo-super-awes-alexaskillskitnodejsfact-6YT0UPG98S3 --zip-file fileb://../

The only parts you'll need to change are the name of the zip file (unless you followed me step-by-step and gave your zip file the same name as mine) and the function name. You'll find the name of your lambda function on the screen where all your functions are listed.

Lambda function name.

When you run the command, you should see something like this:

Confirmation of lambda deployment.

If you see one of the following errors, it means:
  1. You don't have your AWS credentials set up on your machine.

Lambda deployment error.

2. You don't have your default region set on your machine.

Missing default region.

If you're not sure how to resolve either of these issues, refer to Setting Up Your AWS Credentials for help.

Finally, all we need to do now is to return to our Lambda function in AWS and see if that change we made locally is there. You should see the following modal when you return to your function which makes it pretty obvious the deployment was successful.

Succesful lambda deployment.

Click on 'Use remote' and then look for whatever change you made.

Checking the code change in aws.

And it's as simple as that! From now on, you can work locally and then simply create a zip file and deploy it! This is particularly handy for projects over 10MB. Once your project exceeds that size, you'll lose the ability to edit inline in the AWS console.

Share this post: