Home > Net >  AWS - Unable to create Localstack DynamoDB table from JSON
AWS - Unable to create Localstack DynamoDB table from JSON

Time:09-27

I have a DynamoDB JSON file that looks like this:

{
    "AttributeDefinitions": [
        {
            "AttributeName": "pk",
            "AttributeType": "S"
        },
        {
            "AttributeName": "sk",
            "AttributeType": "S"
        }
    ],
    "TableName": "MYTABLE",
    "KeySchema": [
        {
            "AttributeName": "pk",
            "KeyType": "HASH"
        },
        {
            "AttributeName": "sk",
            "KeyType": "RANGE"
        }
    ],
    "GlobalSecondaryIndexes": [
        {
            "IndexName": "GSIReverseIndex",
            "KeySchema": [
                {
                    "AttributeName": "pk",
                    "KeyType": "RANGE"
                },
                {
                    "AttributeName": "sk",
                    "KeyType": "RANGE"
                }
            ],
            "Projection": {
                "ProjectionType": "ALL",
                "NonKeyAttributes": [
                    ""
                ]
            },
            "ProvisionedThroughput": {
                "ReadCapacityUnits": 1,
                "WriteCapacityUnits": 1
            }
        }
    ],
    "BillingMode": "PROVISIONED",
    "ProvisionedThroughput": {
        "ReadCapacityUnits": 1,
        "WriteCapacityUnits": 1
    },
    "StreamSpecification": {
        "StreamEnabled": true,
        "StreamViewType": "NEW_AND_OLD_IMAGES"
    },
    "TableClass": "STANDARD"
}

I am trying to create the corresponding DynamoDB table in Localstack by running the following command:

aws dynamodb create-table --endpoint-url http://localhost:4566 --region us-east-1 --cli-input-file file:///MY_TABLE.json

However, when I run this command I get an error saying:

aws: error: the following arguments are required: --attribute-definitions, --table-name, --key-schema

All of those items are present in the JSON file. Why doesn't the cli like the command?

CodePudding user response:

It seems that the option --cli-input-file is not supported.

You should use --cli-input-json or --cli-input-yaml instead:

aws dynamodb create-table \
 --endpoint-url http://localhost:4566 \
 --region us-east-1 \
 --cli-input-json file://MY_TABLE.json

Note that:

  • I removed a leading slash in the input file path
  • Your table schema is still incorrect, you have to define a non-empty list of NonKeyAttributes for GSI projection
  • Related