rds-api

command module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2019 License: AGPL-3.0 Imports: 2 Imported by: 0

README

rds-api

This API provides simple restful API access to Amazon's RDS service.

Usage

This API uses the standard format for input and output of parameters as defined by the AWS SDK (for reference see https://docs.aws.amazon.com/sdk-for-go/api/service/rds/).

Config

You can define multiple accounts in your config.json file which are mapped to endpoints by the API and allow RDS instances to be created in different AWS accounts. See example config

In each account you can optionally define certain defaults that will be used if those parameters are not specified in the POST request when creating a database:

  • defaultSubnetGroup - the subnet group that will be used if one is not given
  • defaultDBParameterGroupName - map of ParameterGroupFamily to ParameterGroupName's
  • defaultDBClusterParameterGroupName - map of ParameterGroupFamily to ClusterParameterGroupName's

Note that any default parameters need to refer to existing resources (groups), i.e. they need to be created separately outside of this API.

Creating a database

You can specify both database cluster and instance information in the POST to create just an instance or a cluster and a member instance.

For example, to create a single Postgres database instance:

POST http://127.0.0.1:3000/v1/rds/{account}
{
   "Instance":{
      "AllocatedStorage":20,
      "AutoMinorVersionUpgrade":true,
      "BackupRetentionPeriod":0,
      "DBInstanceClass":"db.t2.small",
      "DBInstanceIdentifier":"mypostgres",
      "Engine":"postgres",
      "MasterUserPassword":"MyPassword",
      "MasterUsername":"MyUser",
      "PubliclyAccessible":false,
      "StorageEncrypted":true
   }
}

All instance creation parameters are listed at https://docs.aws.amazon.com/sdk-for-go/api/service/rds/#CreateDBInstanceInput

To create an Aurora cluster with one database instance:

POST http://127.0.0.1:3000/v1/rds/{account}
{
   "Cluster":{
      "AutoMinorVersionUpgrade":true,
      "BackupRetentionPeriod":1,
      "DBClusterIdentifier":"myaurora",
      "Engine":"aurora",
      "MasterUserPassword":"MyPassword",
      "MasterUsername":"MyUser",
      "StorageEncrypted":true,
      "VpcSecurityGroupIds":[
         "sg-12345678"
      ]
   },
   "Instance":{
      "DBClusterIdentifier":"myaurora",
      "DBInstanceClass":"db.t2.small",
      "DBInstanceIdentifier":"myaurora-1",
      "Engine":"aurora",
      "PubliclyAccessible":false
   }
}

All cluster creation parameters are listed at https://docs.aws.amazon.com/sdk-for-go/api/service/rds/#CreateDBClusterInput

Getting details about a database

To get details about a specific database instance:

GET http://127.0.0.1:3000/v1/rds/{account}/mypostgres
{
  "DBInstances": [
    {
      "AllocatedStorage": 20,
      "AutoMinorVersionUpgrade": true,
      "AvailabilityZone": "us-east-1d",
      "BackupRetentionPeriod": 0,
      "DBClusterIdentifier": null,
      "DBInstanceClass": "db.t2.micro",
      "DBInstanceIdentifier": "mypostgres",
      "DBInstanceStatus": "available",
      "Endpoint": {
        "Address": "mypostgres.c8ukc5s0qnag.us-east-1.rds.amazonaws.com",
        "HostedZoneId": "Z3R2ITVGPH62AM",
        "Port": 5432
      },
      ...
    }
  ]
}

To get details about all database instances in the given account (to list both database instances and clusters you can add all=true query parameter):

GET http://127.0.0.1:3000/v1/rds/{account}[?all=true]
Modifying database parameters

You can specify either cluster or instance parameters in the PUT to modify a cluster or an instance.

For example, to change the master password for an Aurora cluster:

PUT http://127.0.0.1:3000/v1/rds/{account}/myaurora
{
   "Cluster": {
      "MasterUserPassword": "EXAMPLE",
      "ApplyImmediately": true
   }
}
Updating tags for a database

You can pass a list of tags (Key/Value pairs) to add or updated on the given database. If there is an RDS cluster and instance with the same name, the tags for both will be updated.

PUT http://127.0.0.1:3000/v1/rds/{account}/myaurora
{
   "Tags": [
      {
         "Key": "NewTag",
         "Value": "new"
      }
   ]
}
Deleting a database

By default, a final snapshot is not created when deleting a database instance. You can override that by adding snapshot=true query parameter.

DELETE http://127.0.0.1:3000/v1/rds/{account}/mypostgres[?snapshot=true]

The API will check if the database instance belongs to a cluster and will automatically delete the cluster if this is the last member.

Development

  • Install Buffalo framework (v0.13+): https://gobuffalo.io/en/docs/installation
  • Run buffalo setup to install required dependencies
  • Run buffalo dev to start the app locally
  • Run buffalo tests -v to run all tests

To build a container locally for testing:

$ cd docker/
$ docker-compose up -d
$ curl http://localhost:8088/v1/rds/ping
pong
# do your work, then shut it down
$ docker-compose down

Authors

Tenyo Grozev tenyo.grozev@yale.edu

Powered by Buffalo

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
rds

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL