Friday, 13 December 2019

Amazon DynamoDB in AWS(Amazon Web Services)

In this article,we will see Amazon DynomoDB in AWS.
  1. Create one role and attached to source “Amazon EC2” and Destination “Amazon DynamoDB FullAccess”.
  2. Launch DynamoDB Web Server and Attach Role “Dynamodb”.
  3. Connect to Dynamo DB Web Server through putty.
  4. Run 2 commands(AWS SDK for PHP-Install by using composer) inside html folder.
  5. Go to dynamodb directory  open createtables.php and uploaddata.php  files and change the required region(ap-south-1).
  6. Create tables and upload data into dynamoDB.
What is DynamoDB?
It is a fully managed NoSQL Database Service
Not to worry about maintenance or administration
Helps in creating databases that can restore any amount of data and
serve any level of request traffic.
How DynamoDB works?
In DynamoDB, tables, items, and attributes are the core components that you work with.
A table is a collection of items, and each item is a collection of attributes.
DynamoDB uses primary keys to uniquely identify each item in a table and secondary indexes to provide more querying flexibility.
First, we need to AWS Console page by using below link.
Click on sign in to Console button.
Logging to aws account
Login using username & password and click on sign in.
Enter to AWS Management Console
We can see the AWS Management Console Dashboard.
Go to services and click on IAM under security, identity & Compliance.
Create Role and attached to source “Amazon EC2” and Destination “Amazon DynamoDB FullAccess” 
Go to Roles and click on Create role.
Choose Source  
Choose EC2 service and click on Permissions.
Provide Destination Permission to the role
Select AmazonS3FullAccess by searching S3Full in search bar and click on Tags.
Click on Review.
Specify Role name “Dynamodb” and click on Create role.
The Role has been created successfully with the name of “Dynamodb”.
In this Role, Source is “EC2” and Destination is “AmazonDynamodbFullAccess”.
Launch DynamoDB Web Server and Attach Role “Dynamodb”
Launch DynamoDB Web Server 
Go to Services, under the compute module click EC2 service to open.
Create and Configure a Virtual Machine
We can see EC2 Dashboard by default one security group is available and click on Launch Instance.
Choose an Amazon Machine Image (AMI)
Select the Operating system of the EC2 instance by choosing any of the Amazon Machine Images (AMI). Select the Microsoft Amazon Linux AMI.
Choose an Instance type
Choose the Type of instance depending on your requirements.
Instance types comprise of varying combinations of CPU, memory, storage, and networking capacity so you can choose the appropriate mix for your applications.
select the default option of t2. micro – this instance type is covered within the free tier. Then click on Configure Instance Details
Click on Configure Instance Details.
Configure Instance Details
Configure EC2 instance details as per requirements of your environment
Go to IAM role and choose the required role “Dynamodb” which was created earlier.
Go to Advanced Details and we type some commands in userdata then click on Review and Launch.
The commands are
#!/bin/bash
sudo su
yum update -y
yum install httpd php git -y
service httpd start
chkconfig httpd on
cd /var/www/html
echo “Dynamo DB” > test.php
Add Storage
Here, we can see root volume by default and size of 8GB
Add a new volume if required
Click on Add Tags.
Add Tags
Tags assist in easier identification and classification of the various instances in your AWS environment.
Click on click to add a Name tag to provide name for our server.
Provide the name for the Linux virtual machine for easier understanding and click on Configure Security Groups.
Configure Security Group
A security group allows configuring firewall rules to allow traffic as needed. Only one rule has been added to allow remote connection.
Add SSH  – open to My IP  and HTML – open to Anywhere and click on Review and Launch.
Review Instance Launch
Review and confirm the configuration of the instance. Click on the Edit button on each configuration item to make changes and click on Launch.
Choose existing Key Pair and Launch Your Instance
To connect to your virtual machine, you need a key pair. A key pair is used to log into your instance and select existing key pair
click on View Instances to view the instance you have just created and see its status.
We can see created instance
Copy Public IP of the DynamoDB.
Search  Public IP/test.php in the browser.
Connect to Dynamo DB Web Server through putty
Open Linux terminal of Dynamodb WebServer.
Run 2 commands(AWS SDK for PHP-Install by using composer) inside html Directory.
Go to /var/www/html Directory
First Command “curl -sS https://getcomposer.org/installer | php”
Second Command “php composer.phar require aws/aws-sdk-php”
Go to dynamodb directory  open createtables.php and uploaddata.php  files and change the required region(ap-south-1)
Go to dynamodb directory and verify files
Open createtables.php file and change the required region(ap-south-1)
Open uploaddata.php change required region (ap-south-1)
Create tables and upload data into dynamoDB.
Search PublicIP(EC2)(13.126.235.154)/dynamodb/createtables.php in browser.
Verify tables in DynamoDB
Go to services , click on DynamoDB  in Database Module.
We can see the some created tables which was created by using “13.126.235.154/dynamodb/createtables.php”
Verify data inside the tables
Currently,there is no data inside the tables.
Upload data into tables
Type PublicIP(EC2)(13.126.235.154)/dynamodb/uploaddata.php in browser.
We can see the data inside the tables which was created by using “13.126.235.154/dynamodb/uploaddata.php”
Connect to Dynamo DB Server Linux CLI to manage  AWS Account 
If you Connect to Dynamo DB Server Linux CLI to manage  AWS Account, we have to run “aws configure” command.
Then it will ask the credentials.
Verify table to run below command

No comments:

Post a Comment