Accessing AWS cloud for test data


In most of the projects today, you see that code + data is stored in the cloud. Global players like Amazon, Microsoft and Google are offering their cloud services. As a test analyst, you might be required to write tests that access data from the cloud.

I faced a similar situation when the team I joined had their project in Amazon AWS. I was writing API tests using Rest Assured and I had to access the database for validation.

I am providing a sample, generic method here which people can use if faced with a similar situation.

First, from command line, you have to login to AWS, which saves the AWS token in your computer.
From your IDE ( I use IntelliJ Idea), go to terminal ( command line) and login to aws credentials.
Use your appropriate company name and user names.

$ -auth l
Username: l@.com
Password: ********


Select an account:
[0] -production-dev
[1] --preproduction-admin
[2] --production-poweruser
Selection: 0

Selected role: --production-dev
Saved AWS token ✔ (/Users//.aws/credentials [Profile=default]) 

I am using java and created the class called DatabaseAccess.java
I am using AP_SOUTHEAST_2, and you could use your own region where domain is hosted.
The table name is "SIT_Registrations" and you could use your own table here. The same with the registration Id. Remember we are using a scan here and we can get multiple values.

To further use it in your test, you would modify the method getRegistration from void to "ScanResult" and return the ScanResult to the calling method.

import com.amazonaws.regions.Regions;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.model.*;
import java.util.HashMap;

public class DatabaseAccess {
    AmazonDynamoDB client;
    DynamoDB dynamoDB;

    public DatabaseAccess() {
        client = AmazonDynamoDBClientBuilder.standard().withRegion(Regions.AP_SOUTHEAST_2).build();
        dynamoDB = new DynamoDB(client);
    }

    public void getRegistration() {
        String tableName = "SIT_Registrations";
        HashMap scanFilter = new HashMap<>();
        String registrationId = "22343cc-bf10-4f7f-ab45-2e33dcasde7e";
        Condition condition = new Condition()
                .withComparisonOperator(ComparisonOperator.EQ.toString())
                .withAttributeValueList(new AttributeValue(registrationId));
        scanFilter.put("requestId", condition);
        ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter);
        ScanResult scanResult = client.scan(scanRequest);
        System.out.println("Result: " + scanResult);
    }
}

Comments

  1. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.

    AWS Training in Bangalore|

    ReplyDelete
  2. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.

    AWS Training in chennai|

    ReplyDelete

Post a Comment

Popular posts from this blog

The pesky scrollbars on Remote desktop - Finally fixed!!

Exploring RedCritter - website for Agile project mangement

API Testing with Rest Assured - Validating the json schema