Dynamo DB

What's New

Amazon DynamoDB Update – Global Tables and On-Demand Backup

AWS adds Global Tables feature to share data across multiple geographies i.e. multi-region and multi-master read\writes.

Hands-On Dynamo DB

Download and Run Dynamo DB

a. Download Dynamo DB

Requires JRE > 1.6 [Install Java Ubuntu (sudo apt-get install openjdk-7-jdk)]

b. Extract the contents of the downloaded archive and copy the extracted directory to a location of your choice.

c. To start DynamoDB, open a command prompt window, navigate to the directory where you extracted DynamoDBLocal.jar, and enter the following command:

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb -inMemory

$ java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb -inMemory

Initializing DynamoDB Local with the following configuration:

Port: 8000

InMemory: true

DbPath: null

SharedDb: true

shouldDelayTransientStatuses: false

CorsParams: *

d. You can now start to write applications for dynamo db.

Sign up for Amazon Web Services and create access keys.

You need these credentials to use AWS SDKs.

To create an AWS account, go to https://aws.amazon.com/, choose Create an AWS Account, and then follow the online instructions.

Create access and secret key

a. Login to aws console b. Go to Services --> IAM --> users --> <your id> --> security credentials c. Create access key and secret key d. The access key and secret key be required to manage AWS resources using terraform

Create an AWS credentials file

For more information, see Configuration in the Boto 3 documentation

Alternatively, you can create the credential file yourself.

By default, its location is at ~/.aws/credentials:

[default]

aws_access_key_id = YOUR_ACCESS_KEY

aws_secret_access_key = YOUR_SECRET_KEY

You may also want to set a default region. This can be done in the configuration file.

By default, its location is at ~/.aws/config:

[default]

region=us-east-1

Install AWS boto3 python package

a. Download boto3 tar

wget https://github.com/boto/boto3/archive/1.4.4.tar.gz

b. Install python boto3 package

tar -xzvf boto3-1.4.4.tar.gz

cd boto3-1.4.4

python setup.py install

c. For instructions, see Quickstart in the Boto 3 documentation.

Boto3 is AWS SDK for python

Boto3 github

Install the latest Boto 3 release via

pip: pip install -U boto3

You may also install a specific version:

pip install boto3==1.0.0

Create configuration

a. Create folder ~/.aws

b. Create config file

~/.aws/config

example

[default]

region=us-west-2

c. Create credentials file

~/.aws/credentials

example

[default]

aws_access_key_id = <ACCESS-ID>

aws_secret_access_key = <SECRET_ID>

Using Boto3 with S3

To use Boto 3, you must first import it and tell it what service you are going to use:

s3.py

import boto3

# Let's use Amazon S3

s3 = boto3.resource('s3')

Now that you have an s3 resource, you can make requests and process responses from the service. The following uses the buckets collection to print out all bucket names:

# Print out bucket names

for bucket in s3.buckets.all():

print(bucket.name)

$ python s3.py

deepagar-bucket

Using Boto3 with Dynamo DB

As you work through this tutorial, you can refer to the AWS SDK for Python (Boto) documentation at http://boto.readthedocs.org/en/latest/. The following sections are specific to DynamoDB:

DynamoDB tutorial

DynamoDB low-level client

Working with Items in DynamoDB

Python and DynamoDB

DynamoDB Python docs

References

- Getting Started - Download

- Query Filter

- Working with Queries

- Query Example

- Query Operation

- boto3 example