Thursday, July 10, 2025

AWS Project day 3

Class 64th AWS Project day 3 July 10th

Create one more lambda function 

Step1:Need to create below lambda function 


Step2: Layer which common code in all database connection code every lambda function, instead of calling all the connection every function to over the repeated entry need to use layer
Environment variables DB_HOST,DB_NAME,DB_USER,  DB_PASS
If you stared with Signup go to loacal singup folder code install the msql pip install pymysql -t.
Create one python directory whatever move to pymsql and pyMSql ..executable file to python folder

Zip the python folder  python.zip

Step3:Create the layer ,upload the Signup zip file and click create layer 
ccit-mysqldb-layer

Step4: Creation of RDS database 

Create Mysql steps:

Aurora and RDS> Create database 

Single(A-Z) DB instance deployment (1 instance)

DB Instance Identifier  :Digital-library

Credential Settings >Self managed  > admin /admin1234

DB Instance Class >Burstable Classes :db.t4g.micro

Public access :Yes 

Click Create database 

Step5:

Endpoint :digital-library.c5iyik8mi7ym.eu-west-2.rds.amazonaws.com

User admin 

password:admin1234

Database Schema creaion: CREATE DATABASE IF NOT EXISTS digital_library; USE digital_library;

CREATE TABLE IF NOT EXISTS users ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL, mobile VARCHAR(20) NOT NULL, email VARCHAR(100) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, gender VARCHAR(10), location VARCHAR(100), image VARCHAR(255) );

CREATE TABLE IF NOT EXISTS books ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, author VARCHAR(255), available BOOLEAN DEFAULT TRUE );

CREATE TABLE IF NOT EXISTS history ( id INT AUTO_INCREMENT PRIMARY KEY, user_id INT, book_id INT, borrow_date DATETIME, return_date DATETIME, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (book_id) REFERENCES books(id) ON DELETE CASCADE );

INSERT INTO books (title, author, available) VALUES ('Wings of Fire', 'A.P.J. Abdul Kalam', TRUE), ('The Guide', 'R.K. Narayan', TRUE), ('Godan', 'Munshi Premchand', TRUE), ('Train to Pakistan', 'Khushwant Singh', TRUE), ('Ignited Minds', 'A.P.J. Abdul Kalam', TRUE), ('Mahabharata', 'Ved Vyasa', TRUE), ('Python Crash Course', 'Eric Matthes', TRUE), ('Digital Fortress', 'Dan Brown', TRUE), ('You Can Win', 'Shiv Khera', TRUE), ('Zero to One', 'Peter Thiel', TRUE);

Step6: add environment variabe 
Environment variables DB_HOST:digital-library.c5iyik8mi7ym.eu-west-2.rds.amazonaws.com
      ,DB_NAME=digital_library,DB_USER=admin ,DB_PASS=admin1234

Step6: Give Connection details to the lambda function click save

Step7: add Layer 

Step8: Select custom layer ,select you layer and version click add 










Step9:Every function add the code deploy and add the environment variable all the remaining functions


Step10:


Step11: Create API Gateways 
Rest API  Click Build  Click Create API

Step12:Create Resource the API,Signup,select below options Create resource 
Step13:Delete the Option methos, create new method for Get method

Step14: Select below option for Signup API choose correspinding lambda function create create method

Step15: Create resouce Signin Click create resource 

Step16:Delete the exist Option metho,Click create method for Signin Click 

Step17:Need create all resource and create methods.


Step18:Create Deploy API ,after deploy all the url copy from the method,past them in you main 
app.py file


Step19:Copy all url from the API,past that into your code


Step20:Modify the exist project code ,like below and execute

Step21: We missed Integration Input parameter adding Signup Click Save 
Step22:Signin Integration mapping templated 
{
  "email": "$input.params('email')",
  "password": "$input.params('password')"
}


Step23: After changes Click deploy API










Step22:


Step23: Data inserted Successfully 

Step24: Every not required upload lambda function runtime file to All lambda function instead of them you just add the layer for the every lambda function
Added the layer customize

 Add same layer similar all database connection lambda function click add


This is the completed Code 





--Thanks


No comments:

Post a Comment