Dynamodb Part1
Class 52nd AWS Dynamo db June 25th
- Dynamodb
- Lambda
Practical:
Login page create using python code, database MySQL and dynamodb
https://github.com/Vakatisubbu/DigitalLibrary/
Step1: Create one Ec2-instance Windows
Public:35.177.182.236 Private:172.31.35.150
Step2: Create RDS database free tier Mysql
Python download and install in Remote desktop windows
https://www.python.org/downloads/
Step3: Copy the Git digitalLibrary
db_config = { 'host': 'msql-sql.csn64oem2jvs.us-east-1.rds.amazonaws.com', 'user': 'admin', 'password': 'admin12345', 'database': 'digital_library' }
-- 2. Use the database
USE digital_library;
-- 3. Create the 'books' table
CREATE TABLE books (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255),
author VARCHAR(255),
available BOOLEAN DEFAULT TRUE
);
-- 4. Insert 10 sample book records
INSERT INTO books (title, author, available) VALUES
('To Kill a Mockingbird', 'Harper Lee', TRUE),
('1984', 'George Orwell', TRUE),
('The Great Gatsby', 'F. Scott Fitzgerald', FALSE),
('Pride and Prejudice', 'Jane Austen', TRUE),
('The Catcher in the Rye', 'J.D. Salinger', TRUE),
('The Hobbit', 'J.R.R. Tolkien', FALSE),
('The Alchemist', 'Paulo Coelho', TRUE),
('The Da Vinci Code', 'Dan Brown', TRUE),
('The Kite Runner', 'Khaled Hosseini', TRUE),
('Harry Potter and the Sorcerer\'s Stone', 'J.K. Rowling', FALSE);
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
mobile VARCHAR(15),
email VARCHAR(255),
password VARCHAR(255),
gender VARCHAR(10),
location VARCHAR(255),
image VARCHAR(255)
);
CREATE TABLE 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 );
Step4: you have to run the app.py file in remote desktop
C:\DigitalLibrary>python app.py Traceback (most recent call last): File "C:\DigitalLibrary\app.py", line 1, in <module> from flask import Flask, request, render_template, redirect, session, url_for, flash ModuleNotFoundError: No module named 'flask'
getting error you need install the below package prior to that
pip install mysql-connector-python
pip install requests
pip install boto3
Step5:run the app.py file ,signup with detail , and login with out details.
C:\DigitalLibrary>python app.py * Serving Flask app 'app' * Debug mode: offWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on all addresses (0.0.0.0) * Running on http://127.0.0.1:5000 * Running on http://172.31.35.150:5000
Step6: once you singup the details are stored in the local mysql
Step7: sign in with your credential and user
Click go to page ,try to borrow some book and retrun some books and test
Step8:mysql history table data was captured.
Previous example we have used mysql,need to mention all the tables creation prior insert,
dynamodb we have more flexible ,Horizontal scaling
Step1:Create Dynamo db users table
Step2:Create table books id,sortkey title create table
Step3:Create table history,sortkey book_id create table
Step4: Tables are create here the problem is id auto increase not exists ware as mysql ,we have to give id manually.
- What is the serverless computing?
Instead you focus on writing code and defining how your application should run. AWS handles the provisioning, scaling, and management of servers automatically.
Here’s How the serverless model works in AWS:
No server management: You don’t need to worry about provisioning, configuring, or managing servers. AWS takes care of the infrastructure needed to run your application
Automatic Scaling: Serverless service automatically scale up or down based on demand. This means you application can handle varying loads without manual intervention.
Event Driven: Serverless architecture often work with event. For instance, AWS lambda functions are triggered by events such as changes in data, HTTP requests or message in a queues.
Pay as you go: You only pay for actually use, based on the number of request and the duration of code execution,rather than paying for a fixed amount of server capacity.
Built in high Availability:Serverless services are designed to be highly available, with redundancy and fault tolerance built in,so you don’t need to manage this yourself.
Focus on code: Developers can focus on writing and deploying code rather than managing servers or scaling or scaling infrastructure. This accelerated development and reduces operation complexity
- Aws Lambda introduction.
You simply upload you code and lambda takes care of everything required to run and scale it with higl availability
- Cold start in AWS Lambda
- Environment variables configuration
- Role importance in the lambda function
- Create a simple lambda function and trigger with test event
- Event driven architecture.
Step12: We can able debug put print statement in the between python code the text will display in cloud watch,i have added subbu, added and deployed and call the endpoint automatically captured in the log event in cloud watch
No comments:
Post a Comment