How to use the RDSDataService function from aws-sdk

Find comprehensive JavaScript aws-sdk.RDSDataService code examples handpicked from public code repositorys.

82
83
84
85
86
87
88
89
90
91
## Why do I need this?
The [Data API](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html) requires you to specify data types when passing in parameters. The basic `INSERT` example above would look like this using the native `AWS.RDSDataService` class:

```javascript
const AWS = require('aws-sdk')
const data = new AWS.RDSDataService()

/*** Assuming we're in an async function ***/

// INSERT with named parameters
fork icon56
star icon434
watch icon16

0
1
2
3
4
5
6
7
8
9
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.

// Handles trading an inventory item from one player to another player
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient();
const rdsDataService = new AWS.RDSDataService();
const CONFIGURATION_DATA = {
    inventoryDB_ARN: "arn:aws:rds:us-east-1:012345678901:cluster:frogjunction-inventory",
    inventoryDBSecret_ARN: "arn:aws:secretsmanager:us-east-1:012345678901:secret:frogjunction-inventory-database-1-a0aAAA",
};
fork icon2
star icon5
watch icon5

128
129
130
131
132
133
134
135
136
137
 * @param {*} clusterArn
 * @param {*} secretArn
 */
async function selectDatabase(inputs, clusterArn, secretArn) {
  // Database Name Question
  const DataApi = new AWS.RDSDataService();
  const params = new DataApiParams();
  params.awsSecretStoreArn = secretArn;
  params.dbClusterOrInstanceArn = clusterArn;
  params.sqlStatements = 'SHOW databases';
fork icon770
star icon0
watch icon2

108
109
110
111
112
113
114
115
116
117
==[SecretARN]== | The ARN of the secret used to store the database credentials. RDS Data API will access this secret and connect to the database using those credentials. | See the previous lab: [Create an Aurora Serverless DB Cluster](/serverless/create/) at step *2. Create a secret to store the credentials*.

```
// require the AWS SDK
const AWS = require('aws-sdk')
const rdsDataService = new AWS.RDSDataService()

exports.handler = (event, context, callback) => {
  // prepare SQL command
  let sqlParams = {
fork icon40
star icon76
watch icon11

22
23
24
25
26
27
28
29
30
31
  AWS.config.update({
    region: 'us-east-1'
  });
}

var RDS = new AWS.RDSDataService();

var params = {
 awsSecretStoreArn: 'arn:aws:secretsmanager:us-east-1:xxxxxxx:secret:test/dataapi/mysql1-BuztkC',
 dbClusterOrInstanceArn: 'arn:aws:rds:us-east-1:xxxxxxx:cluster:test-aurora-mysql-dataapi',
fork icon0
star icon3
watch icon3

1
2
3
4
5
6
7
8
9
10
AWS.config.update({region: 'us-east-1'});

const createClient = require('data-api-client');

// require('dotenv').config();
// const rdsDataService = new AWS.RDSDataService();

const getDatabaseName = async () => {
    const ssm = new AWS.SSM({region: 'us-east-1'});
    const dbParamKey = '/bookstore/db/name';
fork icon0
star icon2
watch icon1

2
3
4
5
6
7
8
9
10
11
const AWS = require('aws-sdk');

const log = console;

export class Migration {
  private client: typeof AWS.RDSDataService;
  private readonly engine: string;
  private readonly sqlFolder: string;
  private rdsParams: {
    database: string;
fork icon2
star icon0
watch icon1

0
1
2
3
4
5
6
7
8
9
const express = require("express");
const pool = require("../modules/pool");
const router = express.Router();
const {rejectUnauthenticated} = require("../modules/authentication-middleware");
const AWS =  require('aws-sdk');
const RDS = new AWS.RDSDataService({region: 'us-east-2'});

router.get("/:id", rejectUnauthenticated, (req, res) => {
    let params = {
      resourceArn: 'arn:aws:rds:us-east-2:635402171575:cluster:aurora-serverless-trial2',
fork icon0
star icon0
watch icon1