Invoking Functions Locally

Execute Lambda function inside a container through PyCharm Professional.

In this tutorial we are going to run our lambda functions inside a local container.

Docker

invoke_step_1

We are going to use Docker. Docker is an open platform for developing, shipping, and running applications. Docker lets you separate your applications from your infrastructure, so you can deliver software quickly. If you are using Windows then you can use something called Docker Desktop.

Just follow the official documentation for the installation process, and you will be good to go.

Configurations

PyCharm Professional is already running. I will select Run, and then navigate to Edit Configurations.

invoke_step_2

Presently, I must select Event Templates. I will opt for a template named “Hello World”. This particular event will be passed into our Lambda function.

invoke_step_3

Subsequently, I'll proceed to click on SAM CLI and ensure that the option “Build function inside a container” is selected.

Select Apply followed by OK.

invoke_step_4

Then I will goto run and click Run HelloWorld function.

invoke_step_5

If you are running on Windows, then Docker Desktop will prompt for sharing the file. Kindly accept it.

invoke_step_6

As you can see, this is my JSON Response which I received from my lambda function. In the console you will be receiving more information like how much duration it took to execute the function along-with billed duration and max memory used.

This is how we can run and debug our lambda functions locally in our machine.