AWS RDS BatchExecuteStatementRequest

AWS RDS BatchExecuteStatementRequest

我正在尝试使用简单信息更新我的 RDS Aurora 数据库。

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.'
    };
  }
};

这将产生一个错误:

{ 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 }

奇怪的是,如果我只在 parameterSets 中添加一个人,它就可以工作,所以当我尝试拥有多个数组时会发生错误。

我在 AWS 控制台中创建了我的数据库,这是针对它的查询:

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)
);

我在写问题的时候发现了问题,我想我还是会在这里分享。

你不能 AUTO_INCREMENT! 这是错误,只需将其删除,一切正常。

这是几个有趣的小时......