Monday, March 21, 2022

AWS Compute + Networking & Content Delivery - Lambda + API Gateway !


API Gateway

AWS- API Gateway Documentation 

Lambda:

AWS - Lambda Documentation

Lambda:

run code without thinking about servers

developers will ask us: ‘can you deploy our API code on AWS?’ (code will be in python)

then we as devops use AWS lambda service and execute using API Gateway’s methods.

when you have configured the triggers, a function will be created. when you click on the function, it will bring you to amazon API Gateway..

AWS LAMBDA: only pay for the compute time that you consume – there’s no charge when your code is not running.


Example API Gateway with Lambda:

Step 1: Select Lambda service and Click on Create function button.

Step 2: Select the following properties

            Author from Scratch

            Function name: func1

            Runtime: Python 3.6

            Architecture x86_64

Click on Create function button.

Step 3: In the Code Source section you will find some code is written, you can replace the templated API code with the code which you want to execute using API Gateway's methods. (make some changes)

Step 4: If you make the changes in the code then make sure that code is saved using: 

File --> Save 

Step 5: Click on the Deploy button.

Step 6: Add trigger by clicking on Add Trigger button.

Step 7: Add API Gateway in the Trigger configuration

            Create API

            Rest API

            Security: IAM

            Click on Add button

Step 8: Click on the function func1-API link. (This will open the AWS API Gateway Console)

Step 9: Select Any and Go to Action --> Delete method

Step 10: Action --> Create method

Step 11: Under func1 select the method as Get method.

            Integration Type: Lambda function

            Use Lambda Proxy Integer: select the check box

            Lambda function: func1

            Tick use default timeout.

            Click on save button.

Step 12: You will see visualization of GET method execution as per below:



Step 13:  Select Get Method and Click on Action ---> Deploy API

             Select Stage as default

             Click on the Deploy button.

Step 14: Come back to AWS lambda console, click on the API endpoint and you will see your code is being deployed. OR you could just click on test.



No comments:

Post a Comment

Fluentd

Open-source log data collector > why logs? - for compliance (auditing, company, business) - for security (transparency, monitoring, admin...