Open opens a DynamoDB driver. It must connect to a specific database. If database isn't provided, part of the driver cannot function.
(ctx context.Context, _ storepb.Engine, conf db.ConnectionConfig)
| 47 | // Open opens a DynamoDB driver. It must connect to a specific database. |
| 48 | // If database isn't provided, part of the driver cannot function. |
| 49 | func (d *Driver) Open(ctx context.Context, _ storepb.Engine, conf db.ConnectionConfig) (db.Driver, error) { |
| 50 | d.config = conf |
| 51 | d.connCtx = conf.ConnectionContext |
| 52 | |
| 53 | cfg, err := util.GetAWSConnectionConfig(ctx, conf) |
| 54 | if err != nil { |
| 55 | return nil, errors.Wrapf(err, "failed to load AWS config") |
| 56 | } |
| 57 | d.awsConfig = cfg |
| 58 | |
| 59 | var optFns []func(*dynamodb.Options) |
| 60 | // Honor a custom endpoint (e.g. DynamoDB Local) when the data source |
| 61 | // specifies a host. Without this the AWS SDK resolves the real AWS endpoint |
| 62 | // for the region and the configured host:port is silently ignored, routing |
| 63 | // queries intended for a local/compatible endpoint to real AWS. |
| 64 | if endpoint := dynamoDBEndpoint(conf.DataSource); endpoint != "" { |
| 65 | optFns = append(optFns, func(o *dynamodb.Options) { |
| 66 | o.BaseEndpoint = aws.String(endpoint) |
| 67 | }) |
| 68 | } |
| 69 | d.client = dynamodb.NewFromConfig(cfg, optFns...) |
| 70 | return d, nil |
| 71 | } |
| 72 | |
| 73 | // dynamoDBEndpoint returns a custom DynamoDB endpoint URL derived from the data |
| 74 | // source host/port, or "" to fall back to the AWS SDK's default (real AWS) |
nothing calls this directly
no test coverage detected