Go database/sql driver for AWS Athena wraps Athena's AWS SDK to provide go sql driver as you would expect. This allows you to query AWS Athena in same way as any other SQL database.
This driver also allows you to use custom session generators to use bastion accounts or other ways of creating aws session.
go get github.com/bobesa/go-aws-athena
Register the driver trough the go imports, this will allow you to use athena
driver
import _ "github.com/bobesa/go-aws-athena/athenasql"
db, err := sql.Open("athena", "foo=bar")
Driver support multiple attributes to be passed
Database name to operate on. Required for execution
db, err := sql.Open("athena", "db=sampledb")
AWS Region
db, err := sql.Open("athena", "region=eu-west-1")
S3 bucket for results. Supply without s3://
db, err := sql.Open("athena", "s3_bucket=aws-athena-query-results-xxxxxxxx-eu-west-1")
Sessiong Generator to create AWS session. This allows you to use custom session generators
db, err := sql.Open("athena", "session_generator=mysessiongenerator")
To create custom session generator just use athenasql.RegisterCustomSessionGenerator
to provide it.
Function signature is func(cfg athenasql.Config) (*session.Session, error)
.
Config (athenasql.Config
) will provide you with Region, S3 Bucket and other stuff.
import "github.com/bobesa/go-aws-athena/athenasql"
athenasql.RegisterCustomSessionGenerator("mysessiongenerator", func(cfg athenasql.Config) (*session.Session, error) {
return session.NewSession(&aws.Config{
Region: aws.String(region),
})
})
Afterwards you can use it when opening sql db connection
db, err := sql.Open("athena", "session_generator=mysessiongenerator")
- Driver is not written for Exec, only Query
- Original inspirational athena querying gist code: Kartiksura's GitHub Gist