Questions tagged with Database

Content language: English

Sort by most recent

Browse through the questions and answers listed below or filter and sort to narrow down your results.

Login request was received, the username and password were correctly extracted from the request body, and a user with ID 1 was found in the database. The form still 504 fails eventually. my index.js, db.js, users.js, and login.html all seem fine. I'm on Lightsail so unfortunately I've had to use SQL Workbench this whole time. Not sure if there's an issue with the Lightsail to DB communication? It's been a pain to try to figure out Lightsail with the 'module' stuff like databases. users.js : ``` const connection = require('./db'); const bcrypt = require('bcrypt'); const saltRounds = 10; class User { constructor(id, username, password, email, createdAt, updatedAt) { this.id = id; this.username = username; this.password = password; this.email = email; this.createdAt = createdAt; this.updatedAt = updatedAt; } static create(username, password, email) { const now = new Date().toISOString(); const sql = `INSERT INTO loginserver (username, password, email, created_at, updated_at) VALUES (?, ?, ?, ?, ?)`; bcrypt.hash(password, saltRounds, (err, hash) => { if (err) { console.error('Error hashing password:', err); return; } const values = [username, hash, email, now, now]; connection.query(sql, values, (err, result) => { if (err) { console.error('Error creating user:', err); return; } console.log('User created with ID', result.insertId); const user = new User(result.insertId, username, hash, email, now, now); return user; }); }); } static getByUsername(username) { const sql = `SELECT * FROM loginserver WHERE username = ?`; connection.query(sql, [username], (err, results) => { if (err) { console.error('Error getting user by username:', err); return; } if (results.length === 0) { console.log('User not found'); return null; } const { id, username, password, email, created_at, updated_at } = results[0]; console.log('User found with ID', id); const user = new User(id, username, password, email, created_at, updated_at); return user; }); } checkPassword(password) { return new Promise((resolve, reject) => { bcrypt.compare(password, this.password, (err, isMatch) => { if (err) { console.error('Error checking password:', err); reject(err); } else { resolve(isMatch); } }); }); } update() { const now = new Date().toISOString(); const sql = `UPDATE loginserver SET username = ?, password = ?, email = ?, updated_at = ? WHERE id = ?`; const values = [this.username, this.password, this.email, now, this.id]; connection.query(sql, values, (err) => { if (err) { console.error('Error updating user:', err); return; } console.log('User updated with ID', this.id); this.updatedAt = now; return this; }); } delete() { const sql = `DELETE FROM loginserver WHERE id = ?`; connection.query(sql, [this.id], (err) => { if (err) { console.error('Error deleting user:', err); return; } console.log('User deleted with ID', this.id); return; }); } } module.exports = User; ``` index.js : ``` const express = require('express'); const https = require('https'); const socketIO = require('socket.io'); const path = require('path'); const fs = require('fs'); const mysql = require('mysql'); const User = require('./server/users'); const bodyParser = require('body-parser'); const app = express(); const server = https.createServer({ key: fs.readFileSync('/etc/letsencrypt/live/ispeedrun.tv/privkey.pem'), cert: fs.readFileSync('/etc/letsencrypt/live/ispeedrun.tv/fullchain.pem') }, app); const io = socketIO(server); // Add this before the routes app.use((req, res, next) => { console.log('Request received'); next(); }); app.use(express.static(path.join(__dirname, 'views', 'public'))); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.get('/', (req, res) => { res.sendFile(path.join(__dirname, 'views', 'index.html')); }); app.get('/live', (req, res) => { res.sendFile(path.join(__dirname, 'views', 'live.html')); }); const connection = mysql.createConnection({ host: 'ls-7f5846c26112d5a110aa9ce17f20838297ce7c51.cdnunzehdfq0.us-east-2.rds.amazonaws.com', port: '3306', user: 'dbmasteruser', password: '', database: '' }); connection.connect((err) => { if (err) { console.error('Failed to connect to MySQL:', err); return; } console.log('Connected to MySQL database'); }); io.on('connection', (socket) => { console.log('WebSocket connection established'); socket.on('message', (msg) => { console.log('message: ' + msg); io.emit('message', msg); }); socket.on('disconnect', () => { console.log('WebSocket connection closed'); }); }); // add this route to handle form submission app.post('/login', (req, res) => { console.log('Received login request'); console.log('Login request received:', req.body); // Log the received request const { username, password } = req.body; User.getByUsername(username, (err, user) => { if (err) { console.error('Error getting user:', err); res.status(500).send('Internal server error'); return; } if (!user) { res.status(401).send('Invalid username or password'); return; } user.checkPassword(password, (err, isMatch) => { if (err) { console.error('Error checking password:', err); res.status(500).send('Internal server error'); return; } if (!isMatch) { res.status(401).send('Invalid username or password'); return; } res.status(200).send(); // Send a 200 status code to indicate a successful login }); }); }); // Add this after the routes app.use((req, res, next) => { console.log('Response sent'); next(); }); const PORT = process.env.PORT || 6611; server.listen(PORT, () => { console.log(`Server running on port ${PORT}`); }); ``` login.html : ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>iSpeedrun.TV - Login</title> <link rel="stylesheet" href="styles.css"> <style> /* Keep the same styles as index.html */ .main-container { display: flex; flex-direction: row; } .video-container { width: 1280px; height: 720px; margin-right: 20px; } .video-container iframe { width: 100%; height: 100%; } .sidebar { width: 300px; height: 720px; display: flex; flex-direction: column; justify-content: space-between; } .sidebar-item { display: flex; align-items: center; padding: 10px; background-color: #222; color: #fff; font-size: 14px; } .sidebar-item img { width: 60px; height: 60px; margin-right: 10px; } header { display: flex; justify-content: space-between; align-items: center; background-color: #222; color: #fff; padding: 10px; } nav ul { display: flex; list-style: none; padding: 0; margin: 0; } nav li { margin-right: 20px; } nav a { color: #fff; text-decoration: none; font-weight: bold; font-size: 16px; text-transform: uppercase; } nav a:hover { color: #ff0000; } .login-container { background-color: #fff; padding: 40px; border-radius: 10px; width: 70%; margin: 20px auto; box-shadow: 0 0 20px rgba(0, 0, 0, 0.5); } .login-container label { font-size: 20px; margin-bottom: 20px; } .login-container input[type="text"], .login-container input[type="password"] { width: 100%; height: 40px; margin-bottom: 30px; padding: 10px; font-size: 16px; border-radius: 5px; border: none; box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.3); } .login-container button[type="submit"] { display: block; width: 100%; height: 50px; background-color: #e74c3c; color: #fff; border: none; border-radius: 5px; font-size: 18px; cursor: pointer; transition: background-color 0.2s; } .login-container button[type="submit"]:hover { background-color: #c0392b; } #message { font-size: 18px; color: red; margin-bottom: 15px; } </style> </head> <body> <header> <h1>iSpeedrun.TV - Login</h1> <nav> <ul> <li><a href="index.html">Home</a></li> <li><a href="livestream.html">Live Streams</a></li> <li><a href="about.html">About Us</a></li> <li><a href="contact.html">Contact</a></li> <li><a href="login.html">Login</a></li> </ul> </nav> </header> <main class="main-container"> <div class="sidebar"> <div class="sidebar-item"> <img src="https://via.placeholder.com/60x60.png?text=User+1" alt="User 1"> <p>User 1</p> </div> <div class="sidebar-item"> <img src="https://via.placeholder.com/60x60.png?text=User+2" alt="User 2"> <p>User 2</p> </div> <div class="sidebar-item"> <img src="https://via.placeholder.com/60x60.png?text=User+3" alt="User 3"> <p>User 3</p> </div> <div class="sidebar-item"> <img src="https://via.placeholder.com/60x60.png?text=User+4" alt="User 4"> <p>User 4</p> </div> </div> <div class="video-container"> <form class="login-container" action="/login" method="post" id="login-form"> <label for="username">Username:</label> <input type="text" id="username" name="username"> <label for="password">Password:</label> <input type="password" id="password" name="password"> <div id="message"></div> <button type="submit">Login</button> </form> </div> </main> <script> const form = document.getElementById('login-form'); const message = document.getElementById('message'); form.addEventListener('submit', async function(event) { console.log('Form submitted'); event.preventDefault(); // Prevent the form from submitting normally const username = document.getElementById('username').value; const password = document.getElementById('password').value; try { console.log('Sending request to server'); const response = await fetch('/login', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ username, password }), }); console.log('Server responded with status:', response.status); if (response.status === 200) { localStorage.setItem('loggedIn', 'true'); window.location.href = 'index.html'; } else { const error = await response.json(); message.textContent = error.message; } } catch (error) { console.error('Error:', error); message.textContent = 'An error occurred. Please try again.'; } }); </script> </body> </html> ```
0
answers
0
votes
12
views
asked 7 hours ago
We have a encrypted dynamodb table and recently noticed latency on ddb calls, looking further it was actually kms calls that was taking time. So we looked into caching solutions and found that CachingMostRecentProvider as the general suggestion. But would like to know why does CachingMostRecentProvider/MetaStore need a DDB table? Why cannot it store the required data in memory and on expiry can it not fetch using DirectKMS?
1
answers
0
votes
9
views
asked a day ago
Hi All, We just updated our redis cluster in elasticache redis cluster from v7.0.5 to v7.0.7 with dualstack connection and it just went down and keep resetting all incoming connections. After investigation, we found out it may be a bug that can reproduce on all AWS account **expected output**: Everything should works fine after redis upgrade **actual output**: redis cluster keep reset all incoming connections **step to reproduce**: 1. Open a new redis cluster with the following settings: choose "dualstack" in connection section instead of default ipv4 option choose redis v7 2. check if AWS choose v7.0.7, we can only reproduce this in v7.0.7, not v7.0.5 not v6.2 or v6 3. try to connect to this redis cluster and will find out all connection refused. ![use nping to test and get all connection refused](/media/postImages/original/IMaVSxiVvJT1GhzmnQ1kAwFw) Thanks for every folks in AWS User Group Taiwan that help us to narrow down the issue Original Post on Facebook in Chinese Traditional: https://www.facebook.com/groups/awsugtw/posts/5984294404980354/
0
answers
0
votes
121
views
asked a day ago
Hi All, is there anyone tried to configure CloudTrail for Redshift? we are trying to do this to get the IAM user activity who run the query in query editor v2. We have found few docs and followed the steps to configure the CloudTrail, we cant get the logs we are looking forward. https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-tutorial.html https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-a-trail-using-the-console-first-time.html This is the docs we have found to show us CloudTrail can integrate with Redshift. And it can get the log result for the query editor v2. https://docs.aws.amazon.com/redshift/latest/mgmt/logging-with-cloudtrail.html But it doesn't show the steps that how to logging the calls with CloudTrail. Looking forward the guidance from you all, so that we can learn together. Thanks.
0
answers
0
votes
12
views
asked 2 days ago
Hi everyone, I have a question about if i need make a setting or configuration to previse any afectation by summer time change, that as we know, it should not be done anymore Im interesting on RDS, however is good knows if any another service have this problem and need to be configured Thanks in advance.
0
answers
0
votes
7
views
Erick
asked 2 days ago
Hi Team, We created Postgres Aurora read replica for Postgres RDS and enabled performance insights for Aurora read replica. In performance insights for this read replica, it is not tracking DB CPU, SQLs, etc. Can you please help how we can track the metrics correctly through performance insights? Thanks, Tushar
0
answers
0
votes
13
views
asked 2 days ago
Greetings. A while ago I created an Aurora instance to migrate my database, but it had a lot of performance issues. Responses are 2-3 times slower than normal on the current host (digital ocean). How can I improve this?
0
answers
0
votes
9
views
asked 3 days ago
I have an on-premises MySQL database that needs to be migrated to an AWS RDS MySQL database. The on-premises database will be updated regularly, and I want to update the RDS database with the latest records from the on-premises database on a daily basis at a scheduled time. The two databases have schema differences, and I need to modify the data from the on-premises database to match the schema of the RDS database. I will not be performing any analytics on the data, and the RDS database will be used as the database for a web application. Can you suggest an ideal approach for this scenario? Thanks in Advance!
1
answers
0
votes
20
views
Jinali
asked 5 days ago
Im trying to find a way, to make the multi-az cluster read replica, to become writable. Is it even possible? or the only way of "promoting" the read replica, to be writable, is to "failover" the primary instance?
1
answers
0
votes
10
views
asked 6 days ago
We have been providing AR web services since March 17th. Normally, the RDS CPU usage was only up to 4-5%, but there was a history of it using up to 60% today, so we are investigating the cause. Currently, RDS is created in a private area, and we understand that it can only be accessed by EC2 created in the same VPC. We checked the access logs of the Ubuntu EC2, but it seems that only two workers accessed the EC2 with their IP addresses. We are wondering if there is any other way to access the private RDS, and if CPU resources can be used like this when automatic RDS backups are performed. The RDS specification is db.m5.large, and MariaDB and the EC2 specification is c5n.2xlarge Ubuntu. Approximately 1 minute later, CloudWatch logs showed [Warning] Aborted connection numbers to db: 'unconnected' user: 'rdsadmin' host: 'localhost' (Got an error reading communication packets).
1
answers
0
votes
6
views
asked 6 days ago
A question for the AWS professionals. I recently worked with a dev team to create a web app for my business. The infrastructure is aws rds (db.m6i.large, 100% utilization, ondemand, multi-az) s3, and lightsail. Cost are estimated to be $300 p month in the calculator but we are being charged $1000 p month. Anyone know why we are charged so much?
1
answers
0
votes
24
views
Andrew
asked 6 days ago
Redshift gives me the error select table_schema,table_name,LISTAGG(column_name,', ') within group (order by ordinal_position asc) from information_schema.columns where table_name = 'abcde' and table_schema = 'xyz' group by 1,2 i tried to create mytable insert into mytable select table_schema , table_name , ordinal_position as colpos, column_name as ColumnName from information_schema.columns where table_name = 'abcde' and table_schema = 'xyz' group by 1,2 gives me error: Function "has_column_privilege(oid,smallint,text)" not supported. Function "has_column_privilege(oid,smallint,text)" not supported. Function "has_table_privilege(oid,text)" not supported. Function "has_table_privilege(oid,text)" not supported. Function "has_table_privilege(oid,text)" not supported. i would want to acheive this which would will be later used in my stored proc. table_schema , tablename, distkey, sortkey, columns xyz abcde col1 col2,col3 col1,col2,col3,col4,col5,col6,col7 i also tried with select schema_name as databasename,table_name as tablename,ordinal_position as colpos,column_name from pg_catalog.svv_all_columns where database_name='prod123' and schema_name='xyz' and table_name='abcde' order by 1,2,3,4 get the error: Function "has_column_privilege(oid,smallint,text)" not supported. Function "has_column_privilege(oid,smallint,text)" not supported. Failed to get redshift columns from ******* thanks KN
0
answers
0
votes
7
views
KN
asked 6 days ago