Creating a DynamoDB table with a Local Secondary Index using the AWS SDK for Java
As mentioned earlier, we have seen how to create a table with a global secondary index; now, let's see how to create a table with a local secondary index.
Getting ready
To perform this operation, you can use the IDE of your choice.
How to do it…
To get started, create a maven project, and add the AWS SDK dependency to the POM.xml
. Here is the latest version of the AWS SDK for Java:
Create an instance of the
DynamoDB
class and initialize it withProfileCredentialsProvider
:AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); client.setRegion(Region.getRegion(Regions.US_EAST_1)); DynamoDB dynamoDB = new DynamoDB(client);
Create the attribute
definitions
we created earlier for the table creation recipe. Here, we will create the table namedproductTable
with the primary key attributes asid
andtype
:ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<...