Yes, it is possible to check whether transactions are supported by Aurora MySQL when accessed through a Node.js Lambda function.
One way to check is to execute a simple test query that uses a transaction and check for any errors. For example, you can use the following code to check if a transaction is supported:
const mysql = require('mysql2/promise');
exports.handler = async (event, context) => {
// create connection
const connection = await mysql.createConnection({
host: 'your-aurora-mysql-hostname',
user: 'your-username',
password: 'your-password',
database: 'your-database'
});
try {
// execute a transaction
await connection.beginTransaction();
await connection.query('INSERT INTO my_table VALUES (?)', ['Hello World']);
await connection.commit();
console.log('Transaction supported!');
} catch (err) {
console.log('Transaction not supported!', err);
} finally {
// close connection
await connection.end();
}
};
If transactions are supported, the code should output "Transaction supported!" in the CloudWatch logs. If not, it will output "Transaction not supported!" with an error message indicating why the transaction failed.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-08-19 11:00:00 +0000
Seen: 15 times
Last updated: Apr 08 '22
How can multiple queries be merged into a single stored procedure in MySQL?
What does "waiting for handler commit" mean in relation to the slow writes experienced in MySQL 8?
How can Spring Boot and Mysql be utilized for CRUD operations?
How can I use sqlalchemy to merge JSON within a column of mysql?
Retrieve all rows in which two IDs appear for the first time.
What are the benefits of choosing sqlalchemy.types instead of sqlalchemy.dialects.mssql?