Docker: How to create a table for local dynamo DB?

Viewed 10269

I'm trying to create a docker container with local Amazon Dynamo DB. And it actually works. But I can not understand how to create a table for this image in Docker file?

Through the javascript I create a table like this:

var params = {
    TableName: 'UserActivity',
    KeySchema: [ 
        {
            AttributeName: 'user_id',
            KeyType: 'HASH',
        },
        {
            AttributeName: 'user_action', 
            KeyType: 'RANGE', 
        }
    ],
    AttributeDefinitions: [
        {
            AttributeName: 'user_id',
            AttributeType: 'S',
        },
        {
            AttributeName: 'user_action',
            AttributeType: 'S',
        }
    ],
    ProvisionedThroughput: {
        ReadCapacityUnits: 2, 
        WriteCapacityUnits: 2, 
    }
};
dynamodb.createTable(params, function(err, data) {
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response

});

And here is my Docker file:

FROM openjdk:8-jre-alpine

ENV DYNAMODB_VERSION=latest

RUN apk add --update curl && \
    rm -rf /var/cache/apk/* && \
    curl -O https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_${DYNAMODB_VERSION}.tar.gz && \
    tar zxvf dynamodb_local_${DYNAMODB_VERSION}.tar.gz && \
    rm dynamodb_local_${DYNAMODB_VERSION}.tar.gz

EXPOSE 8000

ENTRYPOINT ["java", "-Djava.library.path=.", "-jar", "DynamoDBLocal.jar",  "--sharedDb", "-inMemory", "-port", "8000"]
2 Answers
Related