Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any mock(or local) service of aurora serverless Data Api?

I have replaced the way to connect Database from lambda function.
Previously, the function established a connection to RDS using MySQL module and query via 3306 port.
Currently, I tried to use Data API and I have finished to replace all codes without test.

Now I'm thinking about how to guarantee my codes.

I have a few test codes to connect with local MySQL database running on docker image.
However, Data API cannot connect with local MySQL Database because of no endpoint.

So I want to know is there any service or library to mockup Data API.

This is my docker-compose.yml to run MySQL DB.

services:
  db:
    build: ./docker/mysql
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: $DB
      MYSQL_USER: $USER
      MYSQL_PASSWORD: $PWD
      MYSQL_ROOT_PASSWORD: $ROOT_PWD
    ports:
      - "3306:3306"
    volumes:
      - ./docker/mysql/initdb.d:/docker-entrypoint-initdb.d
      - ./docker/mysql/conf.d:/etc/mysql/conf.d
      - ./docker/log:/var/log/mysql

Previously, the function tried to connect to DB by following code

import * as mysql from 'mysql';
import * as util from 'util';

const connection: mysql.Pool = mysql.createPool({
  connectionLimit: 100,
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  port: Number(process.env.DB_PORT),
  database: process.env.DB_NAME,
  connectTimeout: 60 * 60 * 1000,
  acquireTimeout: 60 * 60 * 1000,
  timeout: 60 * 60 * 1000
});

export async function query(sql: string, param?: Array<any>): Promise<any> {
  const connQueryPromisified = util
    .promisify(connection.query)
    .bind(connection);
  return await connQueryPromisified(sql, param);
}

Currently:

import * as aws from 'aws-sdk';
import {
  ExecuteStatementRequest,
  ExecuteStatementResponse,
  Field,
  SqlParametersList,
  BatchExecuteStatementRequest,
  BatchExecuteStatementResponse,
  SqlParameterSets
} from 'aws-sdk/clients/rdsdataservice';
const RDS = new aws.RDSDataService({ region: 'ap-northeast-1' });
const secretArn = process.env.SECRET_ARN;
const arn = process.env.RESOURCE_ARN;
const dbName = process.env.DATABASE_NAME;

export async function query(
  sql: string,
  param?: SqlParametersList
): Promise<any> {
  const params: ExecuteStatementRequest = {
    secretArn: secretArn,
    resourceArn: arn,
    sql: sql,
    parameters: param,
    database: dbName,
    continueAfterTimeout: true,
    includeResultMetadata: true
  };

  return RDS.executeStatement(params).promise();
}

Does anybody know about the Data API mockup service? or is there any ides to write codes with Data API?

like image 348
anizo Avatar asked Aug 25 '19 23:08

anizo


People also ask

What are some limitations of using Aurora Serverless?

All Aurora Serverless v1 DB clusters have the following limitations: You can't export Aurora Serverless v1 snapshots to Amazon S3 buckets. You can't save data to text files in Amazon S3. You can't use AWS Database Migration Service and Change Data Capture (CDC) with Aurora Serverless v1 DB clusters.

Does Aurora Serverless have read replicas?

What is Aurora Serverless? Aurora serverless provides seamlessly scale up and down its compute and memory. You can pay for how much resources that you have been used. No needs of creating and managing the Read Replica and HA(Multi-AZ).

What is difference between Aurora and Aurora Serverless?

Amazon Aurora and Aurora Serverless are two distinct products from AWS. While Amazon's Aurora lets you use cloud-based computing resources to test and run your applications, the Aurora Serverless is a configuration that enables automated capacity scaling and for connecting applications.

When will Aurora serverless V2 have a data API?

When will Aurora Serverless V2 have a Data API? I've seen that V2 is out now but there is no option to have the data api and the docs say it is only available on V1. The Data API can be enabled for Aurora Serverless v1 DB clusters using specific Aurora MySQL and Aurora PostgreSQL versions only.

How do I Run SQL statements on the Aurora serverless DB cluster?

For information about calling the Data API, see Calling the Data API . With the Data API enabled on your Aurora Serverless DB cluster, you can run SQL statements on the Aurora DB cluster by using the Data API or the AWS CLI. The Data API supports the programming languages supported by the AWS SDKs.

How do I integrate Aurora serverless with other AWS services?

You can also use Data API to integrate Aurora Serverless with other AWS applications such as AWS Lambda, AWS AppSync, and AWS Cloud9. The API provides a more secure way to use AWS Lambda.

Is Aurora serverless the best choice for food delivery companies?

The cost comparison clearly reveals that Aurora Serverless is the better choice for the food delivery company in this example. Despite being cheaper at max capacity ($0.368 vs. $0.56 for 8 ACUs), Aurora would require the company to pay for 8 ACUs all throughout the day even when the database base usage is minimal.


1 Answers

Have a look at local-data-api, it looks like what you're asking for.

It is a Docker image that hosts a Data API proxy and either a Postgres or MySQL instance; you can find pull it for DockerHub, image info is here: https://hub.docker.com/r/koxudaxi/local-data-api, including instructions how to run it.

like image 174
Dan C. Avatar answered Oct 14 '22 03:10

Dan C.