# Testing AWS Lambda functions locally on AWS Workspace

**URL:** <https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884>\
**Category:** AWS Compute Discussion\
**Tags:** docker, lambda\
**Created:** [December 11, 2019, 4:00pm UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884 "2019-12-11T16:00:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![faisal3325](https://awshq.com/letter_avatar_proxy/v4/letter/f/c0e974/32.png) [@faisal3325](https://awshq.com/u/faisal3325)\
**Post date:** [December 11, 2019, 4:00pm UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884/1 "2019-12-11T16:00:52Z")

</div>

Hi fellow AWSRedditors,

I was wondering if there’s any other way apart from AWS SAM to test our AWS Lambda functions with other AWS services coded in?

The problem with AWS SAM:

AWS SAM needs docker to create a container for AWS Lambda. Our AWS Workspace is a Windows Server 2016 Data Center. Since Docker needs Hyper-V for virtualization, I have to enable Hyper-V in my OS. But due to the fact that AWS Workspace doesn’t support virtualization, I cannot enable Hyper-V. Now this sucks. AWS Workspace, a service provided by AWS doesn’t allow you to test one of their other service, AWS Lambda. How can that be? I am pretty sure there’s some other workaround. If not, then AWS needs to do something about this. meh.

EDIT:

[https://www.reddit.com/r/aws/comments/6okwql/do\_amazon\_workspaces\_support\_docker\_for\_windows/](https://www.reddit.com/r/aws/comments/6okwql/do_amazon_workspaces_support_docker_for_windows/)

I have confirmed this while trying to enable Hyper-V from Server configuration.

 ![](https://awshq.com/uploads/default/original/1X/550ff210d0fffbe76ba01b5ed7d9f87391125a9d.png)

**SOLUTION:**

[https://www.reddit.com/r/aws/comments/e98won/testing\_aws\_lambda\_functions\_locally\_on\_aws/fajl216?utm\_source=share&utm\_medium=web2x](https://www.reddit.com/r/aws/comments/e98won/testing_aws_lambda_functions_locally_on_aws/fajl216?utm_source=share&utm_medium=web2x)

* * *

**Related discussions:**

- [Ministack in AWS Summit London](https://awshq.com/t/ministack-in-aws-summit-london/21180)
- [Serverless with HIPAA and VPC](https://awshq.com/t/serverless-with-hipaa-and-vpc/21445)
- [Is there a way to do POC for nitro enclave on local before actually moving to an EC2 instance?](https://awshq.com/t/is-there-a-way-to-do-poc-for-nitro-enclave-on-local-before-actually-moving-to-an-ec2-instance/19289)
- [What is the best and cheapest database solution on aws](https://awshq.com/t/what-is-the-best-and-cheapest-database-solution-on-aws/18998)
- [What are the benefits of using Codeartifact over manually installing Python packages?](https://awshq.com/t/what-are-the-benefits-of-using-codeartifact-over-manually-installing-python-packages/20748)

---

<div class="post-metadata">

**Author:** ![ihaznonayme](https://awshq.com/letter_avatar_proxy/v4/letter/i/50afbb/32.png) [@ihaznonayme](https://awshq.com/u/ihaznonayme)\
**Post date:** [December 11, 2019, 4:33pm UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884/2 "2019-12-11T16:33:05Z")

</div>

This is not specific to WorkSpaces. It is because EC2 does not expose hardware virtualization. This prevents many nested virtualization solutions from running properly. To address this, EC2 offers instances that specifically support containers (there are also native container services, like ECS to fill this need). Since WorkSpaces are intended as desktops, they do not leverage those instance types.

If you end goal is specifically to test lambda and utilize containers on your desktop, I would suggest taking a look at Linux based WorkSpaces. Docker does not require access to the HW virt layer in linux. Also, both lambda and Linux WorkSpaces leverage Amazon Linux 2. So, the native dev env more closely matches the end result. I have been doing most, if not all, of my lambda dev on a Linux WorkSpace for some time now.

---

<div class="post-metadata">

**Author:** ![xrendan](https://awshq.com/letter_avatar_proxy/v4/letter/x/c2a13f/32.png) [@xrendan](https://awshq.com/u/xrendan)\
**Post date:** [December 11, 2019, 6:37pm UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884/3 "2019-12-11T18:37:51Z")

</div>

Really it depends on what exactly you want to test. We’ve looked at integrating [LocalStack](https://github.com/localstack/localstack) into our testing scheme but we didn’t really like the overhead. We’ve ended up doing most of our testing outside of SAM and outside of any service emulation by mocking our AWS calls using [Moto](http://docs.getmoto.org/en/latest/) and that’s worked quite well for us.

Fundamentally, Lambda functions are just functions that take an event (and context) and do something in response to that. It should be relatively easy to test your code away from that.

Another thing to think about is factoring your code so that your lambda handlers are mostly processing the incoming and then deferring to other functions in a separate library or section in your codebase that should be able to be tested independently of the actual lambda handlers

---

<div class="post-metadata">

**Author:** ![1000punchman](https://awshq.com/letter_avatar_proxy/v4/letter/1/a88e4f/32.png) [@1000punchman](https://awshq.com/u/1000punchman)\
**Post date:** [December 11, 2019, 7:32pm UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884/4 "2019-12-11T19:32:26Z")

</div>

Can’t you spin an EC2 instance up to run SAM?

Or you can use Vangrant with a linux on top of a VirtualBox or VMWare. Since VMWare and Virtualbox are level 2 hypervisors, you can run without problems.

---

<div class="post-metadata">

**Author:** ![theWyzzerd](https://awshq.com/letter_avatar_proxy/v4/letter/t/85e7bf/32.png) [@theWyzzerd](https://awshq.com/u/theWyzzerd)\
**Post date:** [December 11, 2019, 7:51pm UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884/5 "2019-12-11T19:51:56Z")

</div>

Check out python-lambda-local. It’s a Python tool that lets you run your Lambda functions in a Lambda environment on your local machine.

[https://pypi.org/project/python-lambda-local/](https://pypi.org/project/python-lambda-local/)

That being said, what is preventing you from testing it as a Lambda in the AWS Lambda console?

---

<div class="post-metadata">

**Author:** ![Financial\_Astronaut](https://awshq.com/letter_avatar_proxy/v4/letter/f/9f8e36/32.png) [@Financial\_Astronaut](https://awshq.com/u/Financial_Astronaut)\
**Post date:** [December 11, 2019, 10:08pm UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884/6 "2019-12-11T22:08:19Z")

</div>

Have you considered using Cloud9? Like others said Docker requires Nested virtualization on Windows because it runs a Linux VM through Hyper-V

---

<div class="post-metadata">

**Author:** ![faisal3325](https://awshq.com/letter_avatar_proxy/v4/letter/f/c0e974/32.png) [@faisal3325](https://awshq.com/u/faisal3325)\
**Post date:** [December 12, 2019, 9:34am UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884/7 "2019-12-12T09:34:24Z")

</div>

> [@ihaznonayme](#):
>
> This is not specific to WorkSpaces. It is because EC2 does not expose hardware virtualization. This prevents many nested virtualization solutions from running properly. To address this, EC2 offers instances that …

Thanks for pointing that out. I looked up more on the virtualization support, found this [https://success.docker.com/article/does-docker-desktop-run-in-vdi](https://success.docker.com/article/does-docker-desktop-run-in-vdi) (TLDR; Docker doesn’t support AWS Workspaces as you said because of the nested virtualization issue). But there’s a version of Windows Server which comes specifically for using containers in, Windows Server 2012 onwards. But the caveat is that AWS doesn’t have an image for Windows Server 201x Base with Container support. But, I can see it in the EC2 Instance, Windows Server 2012-2019 Base with Container support. So I have asked the IT to run up an EC2 instance for me to do this.

Since we also work with Powershell scripts, we cannot leave this Windows Workspace. So Linux is a no no for us.

---

<div class="post-metadata">

**Author:** ![faisal3325](https://awshq.com/letter_avatar_proxy/v4/letter/f/c0e974/32.png) [@faisal3325](https://awshq.com/u/faisal3325)\
**Post date:** [December 12, 2019, 9:35am UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884/8 "2019-12-12T09:35:37Z")

</div>

> [@theWyzzerd](#):
>
> Check out python-lambda-local. It’s a Python tool that lets you run your Lambda functions in a Lambda environment on your local machine. …

Thanks. We want to test our AWS SAM application.

---

<div class="post-metadata">

**Author:** ![faisal3325](https://awshq.com/letter_avatar_proxy/v4/letter/f/c0e974/32.png) [@faisal3325](https://awshq.com/u/faisal3325)\
**Post date:** [December 12, 2019, 9:37am UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884/9 "2019-12-12T09:37:15Z")

</div>

> [@1000punchman](#):
>
> Can’t you spin an EC2 instance up to run SAM? Or you can use Vangrant with a linux on top of a VirtualBox or VMWare. Since VMWare and Virtualbox are level 2 hypervisors, you can run without problems.

Yes, that’s what is the final solution for me. Spinning up an EC2 Instance with “Windows Server 2019 Base with Container”

---

<div class="post-metadata">

**Author:** ![faisal3325](https://awshq.com/letter_avatar_proxy/v4/letter/f/c0e974/32.png) [@faisal3325](https://awshq.com/u/faisal3325)\
**Post date:** [December 12, 2019, 9:40am UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884/10 "2019-12-12T09:40:48Z")

</div>

> [@Financial\_Astronaut](#):
>
> Have you considered using Cloud9? Like others said Docker requires Nested virtualization on Windows because it runs a Linux VM through Hyper-V

Yes, I will be creating a Cloud9 instance on my new EC2 Instance with “Windows Server 2019 Base with Container”.

---

<div class="post-metadata">

**Author:** ![ihaznonayme](https://awshq.com/letter_avatar_proxy/v4/letter/i/50afbb/32.png) [@ihaznonayme](https://awshq.com/u/ihaznonayme)\
**Post date:** [December 12, 2019, 5:38pm UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884/11 "2019-12-12T17:38:58Z")

</div>

> [@faisal3325](#):
>
> Thanks for pointing that out. I looked up more on the virtualization support, found this …

Yes, the EC2 instances with container support are the ones I was mentioning.

On the Linux front, it really depends on the type of PowerShell dev you are doing. I use a Linux WorkSpace to do much of my PS dev these days. It reminds me not to use any modules that MS has yet to port over to .netcore. That has been especially helpful when building Lambda functions in PS. For me it’s also super helpful to be able to split my terminal and have Py,PS,Zsh/Bash all running locally.

---

<div class="post-metadata">

**Author:** ![tandthezombies](https://awshq.com/letter_avatar_proxy/v4/letter/t/8e8cbc/32.png) [@tandthezombies](https://awshq.com/u/tandthezombies)\
**Post date:** [December 17, 2019, 3:23am UTC](https://awshq.com/t/testing-aws-lambda-functions-locally-on-aws-workspace/9884/12 "2019-12-17T03:23:51Z")

</div>

While expensive, bare metal EC2 instances such as the i3.metal or z1d.metal may be an option as they do expose the hardware virtualization flags and allow software like Hyper-V and VMware to run natively.
