2

I am trying to update my RDS Aurora database with simple information.

import * as AWS from 'aws-sdk';
import { BatchExecuteStatementRequest } from 'aws-sdk/clients/rdsdataservice';

const RDS = new AWS.RDSDataService();

export const create = async (event: any) => {
  try {
    const params: BatchExecuteStatementRequest = {
      secretArn: 'arn:aws:secretsmanager:XXXXXXXXXXXXXXXXXXX',
      resourceArn: 'arn:aws:rds:XXXXXXXXXXXXXXXXXXXXX',
      schema: 'PUBLIC',
      database: 'test_db',
      parameterSets: [
          [
            {
              name: 'FirstName',
              value: {
                stringValue: 'Joe',
              }
            },
            {
              name: 'LastName',
              value: {
                stringValue: 'Doe'
              }
            }
          ],
          [
            {
              name: 'FirstName',
              value: {
                stringValue: 'Joyer',
              }
            },
            {
              name: 'LastName',
              value: {
                stringValue: 'Doyer'
              }
            }
          ]
      ],
      sql: 'INSERT INTO test_table (FirstName, LastName) VALUES (:FirstName, :LastName)'
    };

    const res = await RDS.batchExecuteStatement(params).promise();

    console.log({ result: res, params });
    return {
      statusCode: 200,
      body: JSON.stringify(res)
    };
  } catch (err) {

    console.error(err);
    return {
      statusCode: err.statusCode || 500,
      headers: { 'Content-Type': 'text/plain' },
      body: 'Could not create the note.'
    };
  }
};

This will generate an error:

{ BadRequestException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’(’Joyer’, ‘Doyer’)' at line 1 }

The weird part is, it's working if I only add ONE person in parameterSets, so the error occur when I try to have more than one array.

I created my db in AWS console, this is the query for that:

CREATE DATABASE IF NOT EXISTS test_db;
USE test_db;
CREATE TABLE IF NOT EXISTS test_table (
  Id int NOT NULL AUTO_INCREMENT,
  FirstName varchar(255), 
  LastName varchar(255),
  PRIMARY KEY (Id)
);
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Johan Byrén
  • 890
  • 2
  • 13
  • 28

1 Answers1

1

I found the problem while I was writing the question, thought I will share it here anyway.

You can NOT have AUTO_INCREMENT! This was the error, just remove it and everything works.

This was a couple of fun hours.....

Johan Byrén
  • 890
  • 2
  • 13
  • 28