# Creating alternator keyspace using JAVA driver

**URL:** <https://forum.scylladb.com/t/creating-alternator-keyspace-using-java-driver/691>\
**Category:** ScyllaDB\
**Tags:** alternator\
**Created:** [July 12, 2023, 4:14pm UTC](https://forum.scylladb.com/t/creating-alternator-keyspace-using-java-driver/691 "2023-07-12T16:14:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike.tihonchik](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.scylladb.com/mike.tihonchik/32/284_2.png) [@mike.tihonchik](https://forum.scylladb.com/u/mike.tihonchik)\
**Post date:** [July 12, 2023, 4:14pm UTC](https://forum.scylladb.com/t/creating-alternator-keyspace-using-java-driver/691/1 "2023-07-12T16:14:30Z")

</div>

Right now, I am using Python’s boto3 library to create my alternator space:

```auto
dynamodb = boto3.resource('dynamodb', endpoint_url=f'http://{alt_host}:8000',
                          region_name='None', aws_access_key_id='None', aws_secret_access_key='None')

```

According to documentation [Using DynamoDB API in Scylla](https://www.scylladb.com/2020/06/16/scylla-university-using-the-dynamodb-api-in-scylla/) it should support several other languages:

```auto
In this example, we will use the Python language to interact with ScyllaDB
with the Boto 3 SDK for Python. It’s also possible to use the CLI or other 
languages such as Java, C#, Python, Perl, PHP, Ruby, Erlang, Javascript.

```

I was not able to find any examples of this being done in other languages. Anyone can share some code samples, specifically in JAVA (as I am writing my main application in JAVA, I would like to keep it to one language)

---

<div class="post-metadata">

**Author:** ![Marcin\_Maliszkiewicz](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.scylladb.com/marcin_maliszkiewicz/32/37_2.png) [@Marcin\_Maliszkiewicz](https://forum.scylladb.com/u/Marcin_Maliszkiewicz)\
**Post date:** [July 17, 2023, 12:09pm UTC](https://forum.scylladb.com/t/creating-alternator-keyspace-using-java-driver/691/2 "2023-07-17T12:09:04Z")

</div>

DynamoDB doesn’t have a notion of keyspaces, so it’s not possible to create one. Instead just create table, here are some samples from aws sdk (alternator is compatible with dynamodb): [https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example\_code/dynamodb](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/dynamodb).

Additionally some example from our alternator load balancing library should demonstrate where to put unused placeholders as alternator doesn’t use AWS region configuration and endpoints: [https://github.com/scylladb/alternator-load-balancing/blob/master/java/src/main/java/com/scylladb/alternator/AlternatorClient.java](https://github.com/scylladb/alternator-load-balancing/blob/master/java/src/main/java/com/scylladb/alternator/AlternatorClient.java)

---

<div class="post-metadata">

**Author:** ![mike.tihonchik](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.scylladb.com/mike.tihonchik/32/284_2.png) [@mike.tihonchik](https://forum.scylladb.com/u/mike.tihonchik)\
**Post date:** [July 17, 2023, 2:50pm UTC](https://forum.scylladb.com/t/creating-alternator-keyspace-using-java-driver/691/3 "2023-07-17T14:50:56Z")

</div>

I ended up coming up with this code:

```auto
    private static void createAlternatorKeyspaces() {
        AmazonDynamoDB client = AmazonDynamoDBClientBuilder
                .standard()
                .withEndpointConfiguration(
                        new AwsClientBuilder
                                .EndpointConfiguration("http://" + alternatorHost + ":8000", Constants.NONE))
                .withCredentials(provider)
                .build();

        ArrayList<KeySchemaElement> keySchema = new ArrayList<>();
        keySchema.add(new KeySchemaElement().withAttributeName("serial_number").withKeyType(KeyType.HASH));
        keySchema.add(new KeySchemaElement().withAttributeName("issuer_cn").withKeyType(KeyType.RANGE));

        ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>();
        attributeDefinitions.add(new AttributeDefinition().withAttributeName("serial_number").withAttributeType("S"));
        attributeDefinitions.add(new AttributeDefinition().withAttributeName("issuer_cn").withAttributeType("S"));

        CreateTableRequest request = new CreateTableRequest()
                .withTableName("blocked_items")
                .withKeySchema(keySchema)
                .withAttributeDefinitions(attributeDefinitions)
                .withProvisionedThroughput(
                        new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(10L));
        DynamoDB dynamoDB = new DynamoDB(client);
        Table table = dynamoDB.createTable(request);
        System.out.println("Waiting for blocked_items to be created...this may take a while...");
        try {
            table.waitForActive();
        } catch (InterruptedException e) {
            System.err.println("CreateTable request failed for blocked_items");
            System.err.println(e.getMessage());
        }
        System.out.println("CreateTable request succeeded for blocked_items");
    }

```
