Reputation: 352
Hi I am using the following code to fetch various things from DynamoDB using Scala. I am stuck at fetching the table description.
I get the following error when I build my project:
constructor DescribeTableRequest in class DescribeTableRequest cannot be accessed in class dynDBMetadata val tableDescription = ddbClient.describeTable(new DescribeTableRequest("Music"))
package dynDBFetchAPIs
import software.amazon.awssdk.auth.credentials.{AwsBasicCredentials, StaticCredentialsProvider}
import software.amazon.awssdk.http.apache.ApacheHttpClient
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.dynamodb.DynamoDbClient
import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest
class dynDBMetadata {
def dynDBMetadataInit(): Unit = {
regionDetails()
}
def regionDetails(): Unit = {
val ddbClient = getDynDBClient()
val region = Region.US_EAST_1
var tableCount: Int = 0
var tableSize: Map[String, Int] = null
var regionSize: Int = 0
val tableList = ddbClient.listTables().tableNames()
val tableIterator = tableList.iterator()
while (tableIterator.hasNext) {
tableCount = tableCount + 1
tableIterator.next()
}
val descTabReq = new DescribeTableRequest("Music")
val tableDescription = ddbClient.describeTable(descTabReq)
println(tableDescription)
println("Region of AWS DynamoDB: " + region)
println("List of DynamoDB Tables: " + tableList)
println("Count of DynamoDB Tables: " + tableCount)
}
private def getDynDBClient(): DynamoDbClient = {
var awsBasicCredentials: AwsBasicCredentials = null
var dynamoDbClient: DynamoDbClient = null
try {
val accessKey = "****************************"
val secretKey = "****************************"
awsBasicCredentials = AwsBasicCredentials.create(accessKey, secretKey)
dynamoDbClient = DynamoDbClient.builder()
.region(Region.US_EAST_1)
.credentialsProvider(StaticCredentialsProvider.create(awsBasicCredentials))
.httpClient(ApacheHttpClient.builder().build())
.build();
} catch {
case e: Exception => {
e.printStackTrace()
}
}
dynamoDbClient
}
}
Why is the given constructor not accessible when I use Scala?
contents of build.sbt
name := "dynamodb"
version := "0.1"
scalaVersion := "2.11.12"
scalacOptions := Seq("-target:jvm-1.8")
libraryDependencies ++= Seq(
"software.amazon.awssdk" % "dynamodb" % "2.15.1"
)
Upvotes: 0
Views: 240
Reputation: 1160
I believe that happends because class software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest doesn't have a primary constructor.
You should create with the builder, like this
val tableRequest = DescribeTableRequest.builder
.tableName(tableName)
.build
com.amazonaws.services.dynamodbv2.model.DescribeTableRequest instead, does have a primary constructor. So, maybe you've just included a wrong dependency.
Upvotes: 1