I am trying to follow a basic AWS tutorial for interacting with DynamoDB in a java runtime environment on a AWS serverless setup. However, for some reason eclipse is throwing an error when I try to create a new AmazonDynamoDBClientBuilder
I double-checked and I see the proper dependencies documented in POM.xml, however I still keep getting the error "AmazonDynamoDBClientBuilder.standard cannot be resolved to a type"
The code:
package com.serverless.demo.function;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.document.Table;
import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.dynamodbv2.model.KeyType;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType;
public class HelloWorld implements RequestHandler<String, String> {
@Override
public String handleRequest(String input, Context context) {
AmazonDynamoDB client = new AmazonDynamoDBClientBuilder.standard().build();
}
}
Can you post your maven.xml?
You should have the following dependency:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.11.163</version>
</dependency>
Check for the latest version of the archive on mvnrepository [here]
Or alternatively a maven file structured as follows:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.166</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
</dependency>
</dependencies>
You might need to verify that there is some Maven stuff in Eclipse's .classpath
file as well otherwise the Eclipse project won't be aware of these dependencies. You might be able to get Eclipse to sort that out for you automagically by viewing the project's properties, clicking "Maven", and then typing "pom.xml" within the "Active Maven Profile" text box.
You'll need to not specify new
, because the standard()
method performs the instantiation for you:
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With