Skip to content

tomarujjwal/aws-serverlessRestAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Serverless REST API using AWS Lambda and Amazon API Gateway


   
Objective - Create Serverless REST API using AWS Lambda and Amazon API Gateway
- Perform API CRUD operations without having to manage infrastructure with efficient code snippets known as ‘Functions’ in AWS lambda
Approach - Setup a Lambda by creating function and testing the function
- API Integration of lambda function with Amazon API Gateway and test using Postman
- Add trigger for Lambda function
Impact - Successfully created a serverless REST API using AWS Lambda and Amazon API Gateway that is inherently scalable
- Operational efficiency of CRUD operations is increased effectively

Primary Technology: AWS Lambda Service, Amazon API gateway, Postman



Design Thinking Whiteboard in Yellow Blue Basic Style (1)


1. Creating and testing Lambda function

1.1 Creating Lambda function

On the aws console, search and select Lambda from the Services category 1

Click Create a function to create a Lambda function 2

Select Author from scratch and give the function a name 3

Select Runtime as Python 3.9 and x86_64 Architecture. Select Create a new role with basic Lambda permissions as Excution role 4

Click Create function 5

Click Test for testing Lambda function 6

Configure test event and click Save 7 8

Click Test 9 10

1.2 Calling API

Go to JSON placeholder to get sample API 11 12

On aws console, create new file named config.py and add base-url in config.py file 13 14

Import config.py file and requests library in lambda_function. Finally, deploy the function by clicking Deploy 16

1.3 Creating Layers

Go to aws console and click on Layers. Click Add a layer. Finally, click Create layer to create a layer 17 18 19

Create a layer by configuring name, description. 20

Enter the following commands to create a .zip file using terminal:
mkdir pypackages
cd .\pypackages
pwd
Copy the path
pip3 install requests -t
ls
21 22 23 24 25

Create .zip file 26 27

Upload .zip file enter other details and click Create 28 29 30

1.4 Add layer

Go to aws console, click on function name 31

Click on Layers 32

Click Add a layer 33

Select Custom layers and choose the created layer. Click Add 35 36

1.5 Testing

Click on Test button 37 38

2. Integration of lambda function with Amazon API gateway

2.1 Creating Rest API

Go to aws console. Search and select API Gateway from the service category 39

Select REST API and click on Build button 40 41

Choose the protocol. Select REST as protocol. Select New API to create a new API and enter API name, description and Endpoint type. Click Create API to create API 42 43

2.2 Designing API

Click on Actions and select Create Method from the drop-down menu 44

Select GET and setup GET. Select Lambda Function as Integration type and select Lambda function created earlier. Click Save 45 46

2.3 Testing API

click on TEST 47 48 49

2.4 Deploying API

Click on Actions and select Enable CORS from the drop-down menu 50

Click on Enable CORS and replace existing CORS headers button 51 52 53

Click on Actions and select Deploy API from the drop-down menu 54

Select Deployement stage as New Stage and click Deploy 55

3. Testing using Postman

Copy the Invoke URL 56

Paste the copied URL on Postman and select GET. Click Send 57

4. Adding Trigger in Lambda function

Go to aws console and click Add trigger button 58

Select API Gateway and select **Use existing API. Select security as Open and click Add 59 60

5. Testing on Browser

Enter the URL on web browser 61

About

Serverless REST API using AWS Lambda and Amazon API Gateway

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published