Build your first AWS Lambda function and attach an endpoint using AWS Api-gateway !

Shekhar Khandelwal
3 min readJan 16, 2022

--

Go to AWS console and launch lambda management console.

Click on “Create function” button.

Provide the basic details like Function name and runtime language. Select python in the runtime option. Click Create Function.

Once created, you will get a success message.

Scroll down and check the code console.

Click on “Test” and check the function call.

Update the payload, if needed and click “Create”. You will see the response output as success.

Now in order to trigger the lambda function from external applications, add an API to your Lambda function to create an HTTP endpoint that invokes your function. For this, click on “Add trigger”

Select “Api Gateway” from the list of triggers.

Two kind of API’s can be created, HTTP API and REST API. For this sample, lets select HTTP API. As part of security, both IAM and API Key options are available. For now, lets select Open. Click on “Add” button.

You will get a Success message, and all the details like endpoint, apikey etc will be available in the configuration section.

Let’s test the endpoint by calling it through a python application using request module.

import requests
url = "https://ryv7b6l14f.execute-api.us-east-2.amazonaws.com/default/myFirstLambdaFunction"
r = requests.post(url,data={'key1':'value1', 'key2':"value2", 'key3':'value1'})
print(r)
print(r.json())

Happy Learning !

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Shekhar Khandelwal
Shekhar Khandelwal

Written by Shekhar Khandelwal

Data Scientist with a majors in Computer Vision. Love to blog and share the knowledge with the data community.

No responses yet

Write a response