Question:
I tried to update my dynamodb using aws but I am not able to create a dynamodb object or a table object as the import com.amazonaws.services.dynamodbv2.**document**.*
does not register document but it reads all the other imports:
1 2 3 4 5 6 7 8 9 |
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.model.AttributeDefinition; import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; import com.amazonaws.services.dynamodbv2.model.KeyType; import com.amazonaws.services.dynamodbv2.model.ListTablesResult; import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; import com.amazonaws.services.dynamodbv2.model.TableDescription; |
Below is the full class I am using:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import android.Manifest; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.location.LocationManager; import android.os.Bundle; import android.provider.Settings; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.Toast; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import com.amazonaws.services.dynamodbv2.document.Table; import com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec; import com.amazonaws.services.dynamodbv2.document.utils.ValueMap; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Table; import com.amazonaws.services.dynamodbv2.document.TableCollection; import com.amazonaws.services.dynamodbv2.document.Table; import com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec; import com.amazonaws.services.dynamodbv2.document.utils.ValueMap; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Table; import com.amazonaws.services.dynamodbv2.document.TableCollection; import com.amazonaws.services.dynamodbv2.model.AttributeDefinition; import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; import com.amazonaws.services.dynamodbv2.model.KeyType; import com.amazonaws.services.dynamodbv2.model.ListTablesResult; import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; import com.amazonaws.services.dynamodbv2.model.TableDescription; public class LoadingPage extends AppCompatActivity { static AmazonDynamoDBClient dynamoDB; LocationManager locationmanager; private TrackGPS gps; double longitude; double latitude; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_loading_page); gps = new TrackGPS(LoadingPage.this); DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient( new ProfileCredentialsProvider())); Table table = dynamoDB.getTable("ProductCatalog"); Map expressionAttributeNames.put("#A", "Authors"); expressionAttributeNames.put("#P", "Price"); expressionAttributeNames.put("#I", "ISBN"); Map expressionAttributeValues.put(":val1", new HashSet expressionAttributeValues.put(":val2", 1); //Price UpdateItemOutcome outcome = table.updateItem( "Id", // key attribute name 101, // key attribute value "add #A :val1 set #P = #P - :val2 remove #I", expressionAttributeNames, expressionAttributeValues); |
Answer:
I had a similar problem and what I’ve learned is that the availability of, and/or source repositories for, packages can change over time.Therefore, if an import cannot be resolved, the following procedure may help.
- Identify the package that supplies the dependency.
- Locate a source for the package.
- Configure the source with Gradle or Maven.
For my answer, I verified your desired imports against com.amazonaws:DynamoDBLocal:1.11.477
under Kotlin.
From the artifact page at MVNRepository, I selected View All.
This led me to a repository source with the following URL:
Since I was using Kotlin, I added the corresponding repository data to repositories
in my build.gradle.kts
for Gradle.
1 2 3 4 5 6 7 8 9 10 |
// Local DynamoDB. repositories { maven(url = "https://repository.mulesoft.org/nexus/content/repositories/public") } dependencies { implementation ("com.amazonaws:DynamoDBLocal:1.11.477") } |
These imports, for the non-local case, can also be satisfied from the package at:
http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-dynamodb/1.11.564/
Therefore, the following entries also work:
1 2 3 4 5 6 7 8 9 10 |
// Remote DynamoDB. repositories { mavenCentral() } dependencies { implementation("com.amazonaws:aws-java-sdk-dynamodb:1.11.564") } |
After configuring my project for either the local or remote versions, I was able to verify that all of your imports that include “document” were available.