21

I am trying below command after aws

--configure command:

aws dynamodb create-table 
--table-name MusicCollection2 
--attribute-definitions

 AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S --

key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE 

--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

Output: Nothing

Please give suggestion how to create dyanmodb table using AWS CLI.

1
  • In addition to @notionquest's answer, here is a link on the reference Commented Mar 26, 2019 at 11:01

2 Answers 2

52
  1. Create the JSON file create-table-movies.json with the below content

    {
        "TableName": "MusicCollection2",
        "KeySchema": [
          { "AttributeName": "Artist", "KeyType": "HASH" },
          { "AttributeName": "SongTitle", "KeyType": "RANGE" }
        ],
        "AttributeDefinitions": [
          { "AttributeName": "Artist", "AttributeType": "S" },
          { "AttributeName": "SongTitle", "AttributeType": "S" }
        ],
        "ProvisionedThroughput": {
          "ReadCapacityUnits": 5,
          "WriteCapacityUnits": 5
        }
    }
    
  2. Browse to the file path on DOS command prompt (assuming Windows OS) and execute the below command

Creates the table on local DynamoDB:-

    aws dynamodb create-table --cli-input-json file://create-table-movies.json --endpoint-url http://localhost:8000

To create the table on AWS DynamoDB service, please provide the correct region name. If your config is done already, it should work.

aws dynamodb create-table --cli-input-json file://create-table-movies.json --region us-west-2

AWS CLI Configure:-

$ aws configure
AWS Access Key ID [None]: accesskey
AWS Secret Access Key [None]: secretkey
Default region name [None]: us-west-2
Default output format [None]:

Once you execute the above command, it updates the data on your profile (on windows).

C:\Users\<username>\.aws\

Check the following files:-

config   - should have the region name
credentials  - should have access key and secret key

Credentials Sample:-

[default]
aws_access_key_id = aaaadffewe
aws_secret_access_key = t45435egfdg456retgfg

Config File Sample:-

[default]
region = us-east-1
Sign up to request clarification or add additional context in comments.

7 Comments

I am getting below error: CreateTable operation: 'Access' not a valid key=value pair (missing equal-sign) , what i am missing?
Updated answer with all the required details. If you have the details as I mentioned in my answer and still you get some error, then the problem could be on your access keys.
thanks @notionquest can you please give me idea to create more than one table using one json file.
Will check the feasibility. Has your original problem resolved? If yes, please accept the answer.
Unfortunately, I don't see a way to create 2 tables using one JSON file (i.e. command is not accepting the array of create table requests)
|
1

aws dynamodb create-table --table-name contact --attribute-definitions AttributeName=name,AttributeType=S AttributeName=email,AttributeType=S --key-schema AttributeName=name,KeyType=HASH AttributeName=email,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1

Use this command instead.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.