Create and delete AWS Neptune graph databases
go build neptune.go
neptune [api | preprovision]
api - Runs the REST API for claiming and deleting Neptune instances
preprovision - Starts the preprovisioner, which runs every minute and makes sure that there are always the specified number of unclaimed Neptune instances
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/neptune/plans | Get list of available instance plans |
| GET | /v1/neptune/url/:name | Get endpoint, access key, secret key, and region of an instance |
| POST | /v1/neptune/instance | Claim preprovisioned instance - {"plan":"small", "billingcode":"department"} |
| POST | /v1/neptune/tag | Tag a preprovisioned instance - {"resource":"name", "name":"key", "value":"value"} |
| DELETE | /v1/neptune/instance/:name | Delete a preprovisioned instance |
See below for examples.
- "database/sql"
- "encoding/json"
- "errors"
- "fmt"
- "log"
- "os"
- "strconv"
- "strings"
- "time"
- "github.com/aws/aws-sdk-go/aws"
- "github.com/aws/aws-sdk-go/service/iam"
- "github.com/aws/aws-sdk-go/service/neptune"
- "github.com/aws/aws-sdk-go/aws/session"
- "github.com/robfig/cron"
- "github.com/nu7hatch/gouuid"
- "github.com/go-martini/martini"
- "github.com/martini-contrib/binding"
- "github.com/martini-contrib/render"
- "github.com/lib/pq"
go
AWS Credentials
Shared:
- ACCOUNTNUMBER - AWS account number
- BROKER_DB - Postgres database, e.g.
postgres://[usr]:[pwd]@[url]:[port]/[db_name] - REGION - AWS region
Preprovisioner:
- KMS_KEY_ID - AWS KMS key ID for encryption
- NAME_PREFIX
- PROVISION_SMALL - Number of small (db.r4.large) instances to preprovision
- SECURITY_GROUP_ID - AWS VPC security group
- SUBNET_GROUP_NAME - RDS subnet
- RUN_AS_CRON - (optional) if supplied, will create a cron job to run every minute
API:
- PORT - (optional) port to listen on, default 3000
curl hostname:3000/v1/neptune/plans
Response: { "small": "Small DB Instance - 2vCPU, 15.25 GiB RAM - $245/mo" }
curl hostname:3000/v1/neptune/url/name
Response:
{
"NEPTUNE_DATABASE_URL": "name.id.region.neptune.amazonaws.com:8182",
"NEPTUNE_ACCESS_KEY": "ACC3SSK3Y",
"NEPTUNE_SECRET_KEY": "sEcReTkEy",
"NEPTUNE_REGION": "us-west-2",
}
curl hostname:3000/v1/neptune/instance -X POST -d '{ "plan": "small", "billingcode": "department" }'
Response:
{
"NEPTUNE_DATABASE_URL": "name.id.region.neptune.amazonaws.com:8182",
"NEPTUNE_ACCESS_KEY": "ACC3SSK3Y",
"NEPTUNE_SECRET_KEY": "sEcReTkEy",
"NEPTUNE_REGION": "us-west-2",
}
curl hostname:3000/v1/neptune/tag -x POST -d '{ "resource": "name", "name": "key", "value": "value" }
Response: { "Response": "Tag added" }
curl hostname:3000/v1/neptune/instance/name -X DELETE
Response { "Response": "Instance deletion in progress" }