Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit e49460c

Browse files
committed
Added info about system properties in readme
1 parent 6699916 commit e49460c

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ The following parameters can be set as options on the Spark writer object before
9999
- `update` if true items will be written using UpdateItem on keys rather than BatchWriteItem. Default false.
100100
- `throughput` the desired write throughput to use. It overwrites any calculation used by the package. It is intended to be used with tables that are on-demand. Defaults to 100 for on-demand.
101101

102+
## System Properties
103+
The following Java system properties are available for configuration.
104+
105+
- `aws.profile` IAM profile to use for default credentials provider.
106+
- `aws.dynamodb.region` region in which to access the AWS APIs.
107+
- `aws.dynamodb.endpoint` endpoint to use for accessing the DynamoDB API.
108+
- `aws.sts.endpoint` endpoint to use for accessing the STS API when assuming the role indicated by the `roleArn` parameter.
109+
102110
## Running Unit Tests
103111
The unit tests are dependent on the AWS DynamoDBLocal client, which in turn is dependent on [sqlite4java](https://bitbucket.org/almworks/sqlite4java/src/master/). I had some problems running this on OSX, so I had to put the library directly in the /lib folder, as graciously explained in [this Stack Overflow answer](https://stackoverflow.com/questions/34137043/amazon-dynamodb-local-unknown-error-exception-or-failure/35353377#35353377).
104112

1.6 MB
Binary file not shown.

src/main/scala/com/audienceproject/spark/dynamodb/connector/DynamoConnector.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ import org.apache.spark.sql.sources.Filter
3131

3232
private[dynamodb] trait DynamoConnector {
3333

34+
@transient private lazy val properties = sys.props
35+
3436
def getDynamoDB(region: Option[String] = None, roleArn: Option[String] = None): DynamoDB = {
3537
val client: AmazonDynamoDB = getDynamoDBClient(region, roleArn)
3638
new DynamoDB(client)
3739
}
3840

3941
private def getDynamoDBClient(region: Option[String] = None, roleArn: Option[String] = None): AmazonDynamoDB = {
40-
val chosenRegion = region.getOrElse(sys.env.getOrElse("aws.dynamodb.region", "us-east-1"))
42+
val chosenRegion = region.getOrElse(properties.getOrElse("aws.dynamodb.region", "us-east-1"))
4143
val credentials = getCredentials(chosenRegion, roleArn)
4244

43-
Option(System.getProperty("aws.dynamodb.endpoint")).map(endpoint => {
45+
properties.get("aws.dynamodb.endpoint").map(endpoint => {
4446
AmazonDynamoDBClientBuilder.standard()
4547
.withCredentials(credentials)
4648
.withEndpointConfiguration(new EndpointConfiguration(endpoint, chosenRegion))
@@ -54,10 +56,10 @@ private[dynamodb] trait DynamoConnector {
5456
}
5557

5658
def getDynamoDBAsyncClient(region: Option[String] = None, roleArn: Option[String] = None): AmazonDynamoDBAsync = {
57-
val chosenRegion = region.getOrElse(sys.env.getOrElse("aws.dynamodb.region", "us-east-1"))
59+
val chosenRegion = region.getOrElse(properties.getOrElse("aws.dynamodb.region", "us-east-1"))
5860
val credentials = getCredentials(chosenRegion, roleArn)
5961

60-
Option(System.getProperty("aws.dynamodb.endpoint")).map(endpoint => {
62+
properties.get("aws.dynamodb.endpoint").map(endpoint => {
6163
AmazonDynamoDBAsyncClientBuilder.standard()
6264
.withCredentials(credentials)
6365
.withEndpointConfiguration(new EndpointConfiguration(endpoint, chosenRegion))
@@ -75,7 +77,7 @@ private[dynamodb] trait DynamoConnector {
7577
**/
7678
private def getCredentials(chosenRegion: String, roleArn: Option[String]) = {
7779
roleArn.map(arn => {
78-
val stsClient = Option(System.getProperty("aws.sts.endpoint")).map(endpoint => {
80+
val stsClient = properties.get("aws.sts.endpoint").map(endpoint => {
7981
AWSSecurityTokenServiceClientBuilder
8082
.standard()
8183
.withCredentials(new DefaultAWSCredentialsProviderChain)
@@ -101,7 +103,7 @@ private[dynamodb] trait DynamoConnector {
101103
stsCredentials.getSessionToken
102104
)
103105
new AWSStaticCredentialsProvider(assumeCreds)
104-
}).orElse(Option(System.getProperty("aws.profile")).map(new ProfileCredentialsProvider(_)))
106+
}).orElse(properties.get("aws.profile").map(new ProfileCredentialsProvider(_)))
105107
.getOrElse(new DefaultAWSCredentialsProviderChain)
106108
}
107109

0 commit comments

Comments
 (0)