Ask Your Question
3

Is it possible to check whether transactions are supported by Aurora MySql when accessed through a Node.js Lambda function?

asked 2022-08-19 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-04-08 03:00:00 +0000

huitzilopochtli gravatar image

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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2022-08-19 11:00:00 +0000

Seen: 15 times

Last updated: Apr 08 '22