gocloud.dev: gocloud.dev/postgres/awspostgres Index | Examples | Files

package awspostgres

import "gocloud.dev/postgres/awspostgres"

Package awspostgres provides connections to AWS RDS PostgreSQL instances.

URLs

For postgres.Open, awspostgres registers for the scheme "awspostgres". The default URL opener will create a connection using the default credentials from the environment, as described in https://docs.aws.amazon.com/sdk-for-go/api/aws/session/. To customize the URL opener, or for more details on the URL format, see URLOpener.

See https://gocloud.dev/concepts/urls/ for background information.

Code:

// This example is used in https://gocloud.dev/howto/sql/#aws

// import _ "gocloud.dev/postgres/awspostgres"

// Variables set up elsewhere:
ctx := context.Background()

// Replace these with your actual settings.
db, err := postgres.Open(ctx,
    "awspostgres://myrole:swordfish@example01.xyzzy.us-west-1.rds.amazonaws.com/testdb")
if err != nil {
    log.Fatal(err)
}
defer db.Close()

// Use database in your program.
db.ExecContext(ctx, "CREATE TABLE foo (bar INT);")

Index

Examples

Package Files

awspostgres.go

Constants

const Scheme = "awspostgres"

Scheme is the URL scheme awspostgres registers its URLOpener under on postgres.DefaultMux.

type URLOpener Uses

type URLOpener struct {
    // CertSource specifies how the opener will obtain the RDS Certificate
    // Authority. If nil, it will use the default *rds.CertFetcher.
    CertSource rds.CertPoolProvider
    // TraceOpts contains options for OpenCensus.
    TraceOpts []ocsql.TraceOption
}

URLOpener opens RDS PostgreSQL URLs like "awspostgres://user:password@myinstance.borkxyzzy.us-west-1.rds.amazonaws.com:5432/mydb".

func (*URLOpener) OpenPostgresURL Uses

func (uo *URLOpener) OpenPostgresURL(ctx context.Context, u *url.URL) (*sql.DB, error)

OpenPostgresURL opens a new RDS database connection wrapped with OpenCensus instrumentation.

Package awspostgres imports 13 packages (graph). Updated 2019-07-04. Refresh now. Tools for package owners.