Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AmazonDynamoDBClientBuilder.standard cannot be resolved to a type

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();  

    }
}
like image 228
rafiya Avatar asked May 11 '17 16:05

rafiya


2 Answers

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.

like image 55
dutoitns Avatar answered Sep 20 '22 10:09

dutoitns


You'll need to not specify new, because the standard() method performs the instantiation for you:

AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();

like image 36
millems Avatar answered Sep 20 '22 10:09

millems