If you’ve been following my Medium Blog recently, you’ll know that I’m a huge fan of Serverless and I genuinely believe that it will start to seriously take off in terms of popularity in the years to come.
In this tutorial, we are going to be writing a very simple Python based AWS Lambda function that we’ll then deploy using the serverless.com CLI.
In order to install the
serverless CLI you can do the following:
If you have set up your AWS credentials correctly with an account that has full permissions then you will now be able to deploy Lambda functions that sit behind an API gateway with ease.
Create a new directory in which you can add Python files. Within this new directory create a file called
simple.py as well as a
Open up the
simple.py file and create a new function within this called
def hello(event, context):. This
hello() function will be the main entry point for our AWS Lambda function and when we call the endpoint, this is what will be executed.
hello() function, we want to return the string
hello, world back to anyone who calls said lambda function.
Deploying Without Serverless
If you wished, you could deploy this without the serverless CLI, you could do so through using either the
aws-cli or through the console and either uploading your lambda function as a
.zip file or through the inline editor.
Our Serverless.yml File
serverless.yml file we will want to define how we want to expose our lambda function. Let’s step through this line-by-line.
Once we are happy with our function and we have our
serverless.yml defined, we can deploy this function by calling
serverless deploy within the same directory as our
When we run this, you should see the following output:
You should notice the
endpoints list has a
GET request endpoint that you should be able to navigate to now should you wish. When you open this up in a browser, you should see the words
hello, world output to your browser.
Hopefully, you found this tutorial educational! If you require any further assistance then please feel free to let me know in the comments section below!