Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to specify the AWS region #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ Usage

The URL of the entry point for an AWS web service. It is required for AWS DynamoDB and optional for DynamoDB local.

- **region** as *string*, optional

The AWS region of the AWS DynamoDB service.

## CREATE USER MAPPING options

`dynamodb_fdw` accepts the following options via the `CREATE USER MAPPING`
Expand Down
8 changes: 6 additions & 2 deletions connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static void dynamodb_check_conn_params(dynamodb_opt *opt);
static void dynamodb_inval_callback(Datum arg, int cacheid, uint32 hashvalue);
static Aws::DynamoDB::DynamoDBClient *dynamodb_client_open(const char *user,
const char *password,
const char *region,
const char *endpoint);
static void dynamodb_delete_client(Aws::DynamoDB::DynamoDBClient *dynamoDB_client);

Expand Down Expand Up @@ -211,7 +212,7 @@ dynamodb_create_connection(ForeignServer *server, UserMapping *user)
/* verify connection parameters and make connection */
dynamodb_check_conn_params(opt);

conn = dynamodb_client_open(opt->svr_username, opt->svr_password, opt->svr_endpoint);
conn = dynamodb_client_open(opt->svr_username, opt->svr_password, opt->svr_region, opt->svr_endpoint);

if (!conn)
ereport(ERROR,
Expand Down Expand Up @@ -307,14 +308,17 @@ dynamodb_inval_callback(Datum arg, int cacheid, uint32 hashvalue)
* Create dynamoDB handle.
*/
static Aws::DynamoDB::DynamoDBClient*
dynamodb_client_open(const char *user, const char *password, const char *endpoint)
dynamodb_client_open(const char *user, const char *password, const char *region, const char *endpoint)
{
const Aws::String access_key_id = user;
const Aws::String secret_access_key = password;
Aws::Client::ClientConfiguration clientConfig;
Aws::DynamoDB::DynamoDBClient *dynamo_client;
Aws::Auth::AWSCredentials cred(access_key_id, secret_access_key);

if (region)
clientConfig.region = region;

clientConfig.endpointOverride = endpoint;

dynamo_client = new Aws::DynamoDB::DynamoDBClient(cred, clientConfig);
Expand Down
1 change: 1 addition & 0 deletions dynamodb_fdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
typedef struct dynamodb_opt
{
char *svr_region; /* dynamodb region */
char *svr_endpoint; /* dynamodb server ip address */
char *svr_username; /* dynamodb user name */
char *svr_password; /* dynamodb password */
Expand Down
4 changes: 4 additions & 0 deletions option.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static bool is_valid_option(const char *option, Oid context);
static struct DynamodbFdwOption valid_options[] =
{
/* Connection options */
{"region", ForeignServerRelationId},
{"endpoint", ForeignServerRelationId},
{"partition_key", ForeignTableRelationId},
{"sort_key", ForeignTableRelationId},
Expand Down Expand Up @@ -191,6 +192,9 @@ dynamodb_opt *dynamodb_get_options(Oid foreignoid)
{
DefElem *def = (DefElem *) lfirst(lc);

if (strcmp(def->defname, "region") == 0)
opt->svr_region = defGetString(def);

if (strcmp(def->defname, "endpoint") == 0)
opt->svr_endpoint = defGetString(def);

Expand Down