diff --git a/README.md b/README.md index f82885b..b1d93b0 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/connection.cpp b/connection.cpp index 4491647..bd0bcc1 100644 --- a/connection.cpp +++ b/connection.cpp @@ -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); @@ -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, @@ -307,7 +308,7 @@ 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; @@ -315,6 +316,9 @@ dynamodb_client_open(const char *user, const char *password, const char *endpoin 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); diff --git a/dynamodb_fdw.h b/dynamodb_fdw.h index 18ae435..f094df7 100644 --- a/dynamodb_fdw.h +++ b/dynamodb_fdw.h @@ -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 */ diff --git a/option.c b/option.c index c042b95..0fd9f22 100644 --- a/option.c +++ b/option.c @@ -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}, @@ -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);