AWS Lambda: Run Your Code For Free

Alex Gordienko
The Startup
Published in
3 min readOct 15, 2020

We used to deploy our software on physical or virtual servers with pre-installed environments. It is easy to copy your Python script to that machine and run it via the command line. But what if you need this operation to be done once a month within a specific environment. Do we need to prepare a whole computing instance for this small operation? Another example. We need our code executed each time it triggered, but we cannot predict how often it will happen.

Thanks to AWS we have a simple solution. There is a service called AWS Lambda. Based on the information provided on the official page, AWS Lambda lets you run code without provisioning or managing servers — all with zero administration. You can set up your code to automatically trigger from other AWS services or call it directly from any web or mobile app. Let’s see how to set AWS Lambda function to execute Python script from the internet call.

Firstly, go to the Functions page on the AWS Lambda section and click on ‘Create function’ button:

There are many code samples and presets in the Blueprints section. Moreover, we could use a big ready-to-deploy app library in the App Repository section. But we do not need them at the moment, let’s start with a simple ‘hello world’ example. Enter a name for our function and choose runtime environment:

For using RDS inside of our function, you can create a Database Proxy. But you should be noticed that this option does not provide by Amazon for free (even if you have only a free-tier DB instance). Remember, that it is a better idea to save database user credentials in AWS Secrets Manager, not in code. You could use AWS SM for saving user and password and simply call it later to receive this pair by secret key from other services, i.e. from a Lambda function.

Here we go! Our brand new Lambda function is ready to run. But wait, we need to do one more thing — set up a trigger. As I mentioned in the beginning, I want my function to run each time I call it from the web. To do so, click on ‘Add trigger’ button. Select API Gateway with Open type (without authorization). Now click on the new trigger at the left, scroll down and expand the API Gateway trigger. Here we can see an endpoint that can be used for calling our function from the outside:

The coolest thing is that you can run your functions for free forever if you do not reach limits which are 400’000 GB/sec and 1M requests per month. Try it!

--

--