Deploy web application with Lambda, ApiGateway and DynamoDB | AWS Serverless Services

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to my YouTube channel my name is ainash and uh in this video I'm going to discuss about a small project okay so in this specific project I'm going to uh primarily use three components one is Dynamo DB for backend database storage and second one is Lambda it act as a web server so then uh API Gateway it act as a front end okay so when any customer trying to access my application right uh so the request will come to apa Gateway API Gateway is going to read the apay call and it is going to uh processed by the Lambda and even I'm going to read some information I'm going to um uh get whatever information customer is trying to uh enter I'm going to read that information and I'm going to write that information in backend Dynamo DB table okay before uh starting this implementation we have a prerequisite so that we have to create an I am role for this Lambda function so this Lambda function should able to write data to backend Dynamo DB table right so uh we are going to create a role and we're going to associate that role to our Lambda function so as a first step navigate to IM am navigate to roles click on create role I'm going to create a role for this a service called Lambda under use cases select Lambda then click on next so um for this Lambda function what exactly permissions we really required so if You observe so this Lambda basic access execution role is definitely required so this Lambda basic access execution role will provide permission to write the logs whenever any text execution happened so this is basically required also along with this I'm going to use this Dynamo DB full access also and also this Lambda uh invoke function right this permissions Also may required so uh currently I'm going to give Dynamo DB full access or if you have any doubt like you know about this permission you can simply associate administrator access if you if you're facing any issue later okay let me uh click on next and I'm going to give name as U uh admin ion Lambda I role so then click on create role now an I am Ro created so the prerequisite part completed now as a first thing I'm going to uh create a Lambda function and uh then I'm going to create a Dynamo DB table okay so first let's go to Lambda select Lambda and uh click on create function and uh this function name you can give any I'm going to call this as uh aash demo function and runtime I'm using python 3.8 and uh under this execution role the role we have created some time back I'm I'm going to use that admin Lambda role then click on create function all right a Lambda function created and we uh should uh have we should write some code here so I already prepared this code and I'm going to share this code with you guys so these all code are the supported documents it's in this repository so here is a URL I'll also share this URL in our video description so you can simply clone or you go to this project four and here we have a zip file you can simply select this and there you have this download option you can use this download option and download this okay so now um what exactly this um this Lambda function contains so this Lambda function contains actually three files one is contact us page whenever uh a customer trying to access our application first is contact page will open whatever the information he is going to fill right whatever the message is going to write here whenever he click on submit it actually stores in backend database okay currently it's not happening whenever I click on submit nothing happening so uh once that uh he click on submit immediately if the data written successfully to backend Dynamo DB table the success. HTML page is going to load this is what it is okay and also this Lambda function is going to throw an error if like you know in between if we have any errors and all so let me open this Lambda function and let me explain you uh what exactly this is going to do so basically this Lambda function is going to um act as a simple web server so it serves contact us. HTML page you see here it serves contacts. HTML page whenever we get any get request from our API Gateway so it is going to load this contact. HTML and whenever any post request is coming You observe here whenever any stdp method if it is a post request what's happening this success. HTML page is going to load and not only that for this post request what's happening a Dynamo DV U is loading here and in Dynamo DB there is a table name here as a sample one I am calling it as a AAS table okay and uh within this aenas table I'm going to insert all this information whatever the information I'm getting it from this contact us. HTML all that information I'm going to write it in this backend Dynamo DB table okay so this is what this Lambda code is doing and um what I'm doing I'm going to zip all this I'm going to zip all this where is that compress and I'm going to upload okay so our Lambda function name is avinas demo function I'll keep same name for this as well rename all right so you can upload this ZIP file into an S3 bucket and you can uh browse the T3 uh location also here so but the thing is uh whenever you want to use ad option okay so you have to uh whatever the role you Associated to this Lambda function right so to this role you need to give get object permission on the S3 bucket okay right so now let's go to upload then click on zip file click on upload it's on my local laptop AAS demo function. zip so then click on open okay then save now immediately all these files should open here so this Mac OSX uh it comes defaultly whenever we are zipping so I'm just going to delete this not really required so these are the three files is Lambda function success. HTML and contact test.html so contact test.html is loading here and success. HTML is loading here and DB is going to point so now so the Lambda part uh currently completed now let's go to Dynamo DB in Dynamo DB we have an option called tables go to tables option then click on create table so now it's asking me to enter the table name so as for our code our table name should be AAS table I'm going to give same thing as here and what exactly this partition keys so I'm going to use email as a partition key and that's going to be a string so then scroll down so if you want to customize any settings like you know uh you want to choose the storage classes you want want to uh provision this capacity on demand or you want to specify your read capacity units and write capacity units you can uh Define that here but for this demo I'll go with the default settings so then uh scroll down then click on create table all right so now a Dynamo DB table is creating okay it won't take much time so Dynamo DB is going to be very quick so we don't require any clusters so basically the good thing with this architecture is all components are serverless components Lambda is a serverless mechanism Dynamo DB also doesn't require any servers AWS main is a server AP Gateway also serverless so we are completely using serverless mechanism here okay the Dynamo DB table created and do we have any items now so when you go to this explore items when you you select the table do we have any items no we don't have any items let's keep this Dynamo DB aside so now we completed um this Dynamo DB part as well as Lambda part now let's configure API Gateway so let's go to API Gateway and within this API Gateway we have ant option called rest API so this rest API works over the Internet rest rest API private Works only within our VPC okay so click on this rest API click on build so I'm going to create a new API and API name so we can give uh any name like um ainash demo API is a API name I'm giving and API endpoint is going to be regonal not a private okay then click on create API all right so now an API created next option is we need to create methods so if you recall our Lambda function so we are primarily performing um uh here in this Lambda we're primarily performing this get operation and post operation right so we need to configure both methods here uh first go to this uh API then click on create method and under method type we have an option called get so select that get option and Lambda function and make sure you enable this Lambda proxy integration so the if you don't enable this uh uh the request won't send as a structured event and whatever the Lambda function in which region you created whatever the Lambda function you created select the Lambda function so we created this this AAS demo function right I'm selecting it and we are good with the default time out that is 29 seconds at 30th second it is going to time out then click on create method okay so now we have configured get method in same way let's go to this rout and click on create method and now select post select the post and I'm going to use this uh Lambda function make sure you enable Lambda proxy integration Lambda fun function name I'm going to select again then click on create Method All right so we have created uh our required API calls and then we need to deploy this API click on deploy API so the stage you can create a new stage and in simple you can call the stage as a Dev or you can give any name then click on deploy so whenever you complete this deployment you're are going to get an invoke URL so let me copy that invoke URL so this is a invoke URL okay so now whenever we are giving this invoke URL in our browser so it is loading this um web page so again where this web page is actually so it's in Lambda it's in our Lambda function sorry it's here so in Lambda function whatever this cont contact us. HTML we have right whenever we give our API um invocation URL we are getting that page and now I'm going to fill some information okay I'm going to call this as ainash last name as a ready giving my email ID then giving uh a message hello this is my test project on a serverless delivery then click on submit whenever we submitting this yeah if the data uh it's storing in the backend dynamodb table it's going to load so basically this is another web page so this is success. HTML web page so now uh even if you want to try you can uh like a test with another information earlier we have given ainash and it won't accept duplicate values the reason in Dynamo DB we have given email as a primary one right so it won't accept the duplicate values I'm going to give like a name as a test calling it as a YouTube uh ainash a.com this is second test then click on submit whenever we submitted again uh it's displaying that success message now how to verify this so to verify this you first need to go to Dynamo DB uh where is that yeah it's here here is our Dynam DB table and go to explore items when you click on this avinas table and when you give a refresh here You observe whatever the information we have filled there the first name the last name the message you see here that all information is storing here right so whatever the message also uh it's actually storing here in back and Dynamo DB so in same way you can you can fill multiple like let me give um right uh it's trying to read uh previous it's it's trying to submit previous information only okay test test test and test test and submit all right now again go to Dynamo DB give a refresh you see here test test test and it's back and it's storing in Dynamo DP okay so this is what the uh architecture whenever we are trying to access it is hitting AP Gateway and uh the Lambda is taking care about that uh get request or post request and uh it is delivering the required web page via API Gateway and also it is going to store information in backend Dynamo DB table also if you want to give any custom domain names we do we we even have uh in Dynamo DB options like custom domain names so you can give your domain name and you can even associate certificates and then you can create domain and you can map it in your root 53 also all right that is all about uh this project U thanks for watching this video see you again in um next scenario or project thank you
Info
Channel: Avinash Reddy Thipparthi
Views: 1,145
Rating: undefined out of 5
Keywords: Aws avinash reddy, Aws with avinash, Aws telugu, Aws real time projects, Aws projects, Naresh technologies
Id: dsH2QC6O3Gg
Channel Id: undefined
Length: 17min 2sec (1022 seconds)
Published: Mon Nov 20 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.