Cloud Computing‎ > ‎AWS‎ > ‎Dynamo DB‎ > ‎

boto3





#### Connect DynamoDB Table

```
$ python
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
# >>> session = boto3.session.Session(profile_name='aws-profile')
>>> session = boto3.session.Session(region_name='', aws_access_key_id='', aws_secret_access_key='')
>>> dynamodb = session.resource('dynamodb')
>>> table = dynamodb.Table('com.vpc.user')

```

#### List DynamoDB Table

```
>>> response = table.scan()
>>> data = response['Items']
>>> print str(data)
```

#### Create DynamoDB Table

```
ks=[{'AttributeName': 'id','KeyType': 'HASH'}, {'AttributeName': 'name','KeyType': 'RANGE'}]
ass=[{'AttributeName': 'id','AttributeType': 'S'}, {'AttributeName': 'name','AttributeType': 'S'}]
ps={ 'ReadCapacityUnits': 5, 'WriteCapacityUnits': 5    }

table = dynamodb.create_table(TableName='com.vpc.user', KeySchema = ks, AttributeDefinitions = ass , ProvisionedThroughput=ps)

```

#### Insert DynamoDB Table entry

```
item = {'id' : '1234', 'name': 'me', 'metadata': 'none'}
table.put_item(Item=item)
```

#### Delete DynamoDB Table entry

```
key_dict = {'id': '1234', 'name': 'me'}
table.delete_item(Key=key_dict)

```


Comments