1

I am trying to perform a GET of an object on S3 storage using ReadyAPI (or SoapUI).

Here is the documentation for how it is done

In order to make the request I require a "signature" to be generated. How can this be done within the ReadyAPI suite itself?

p.s. The AWS API plugin doesn't currently function for my region (eu-west-1)

1 Answer 1

2

This is really easy if the use of the AWS JDK is an option for you. I tried many hours to generate my own signature for REST API access to AWS. After I discovered the AWS JDK it was a matter of minutes. All can be done with a few lines of groovy script code within ReadyAPI/SoapUI NG.

  • Download, install, configure AWS CLI. (why this? If you configure your secret key in the CLI, the JDK will recognize the configuration and configuration location on your computer and use it)

  • Be on latest version of ReadyAPI/SoapUI

  • Download AWS JDK and unzip

  • Copy aws-java-sdk-x.xx.xx.jar to your ReadyAPI/SoapUI installation Lib folder and restart ReadyAPI/SoapUI

  • Groovy script step code utilizing AWS JDK to list buckets that you have access to(commented out stuff would let you create buckets):

    import com.amazonaws.AmazonClientException;
    import com.amazonaws.AmazonServiceException;
    import com.amazonaws.auth.profile.ProfileCredentialsProvider;
    import com.amazonaws.regions.Region;
    import com.amazonaws.regions.Regions;
    import com.amazonaws.services.s3.AmazonS3;
    import com.amazonaws.services.s3.AmazonS3Client;
    import com.amazonaws.services.s3.model.CreateBucketRequest;
    import com.amazonaws.services.s3.model.ListBucketsRequest;
    import com.amazonaws.services.s3.model.GetBucketLocationRequest;
    
    
    def AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
    //s3client.setRegion(Region.getRegion(Regions.US_WEST_2));
    
    try {
    //   def String bucketName     = "soapui-bucket";
    //   if(!(s3client.doesBucketExist(bucketName))) {
    //      // Note that CreateBucketRequest does not specify region. So bucket is created in the region specified in the client.
    //      s3client.createBucket(new CreateBucketRequest(bucketName));
    //   };
    
       // Get location.
    //   String bucketLocation = s3client.getBucketLocation(new GetBucketLocationRequest(bucketName));
    //   log.info("bucket location = " + bucketLocation);
    
       // A couple of ways to list buckets.
       bucketList = s3client.listBuckets();
       log.info("bucketList All= " + bucketList);
    //   bucketList = s3client.listBuckets(new ListBucketsRequest());
    //   log.info("bucketList Owner= " + bucketList);
    
    }
    catch (AmazonServiceException ase) {
                log.info("Caught an AmazonServiceException, which " +
                        "means your request made it " +
                        "to Amazon S3, but was rejected with an error response" +
                        " for some reason.");
                log.info("Error Message:    " + ase.getMessage());
                log.info("HTTP Status Code: " + ase.getStatusCode());
                log.info("AWS Error Code:   " + ase.getErrorCode());
                log.info("Error Type:       " + ase.getErrorType());
                log.info("Request ID:       " + ase.getRequestId());
    }
    catch (AmazonClientException ace) {
                log.info("Caught an AmazonClientException, which " +
                        "means the client encountered " +
                        "an internal error while trying to " +
                        "communicate with S3, " +
                        "such as not being able to access the network.");
                log.info("Error Message: " + ace.getMessage());
    }
    
    log.info 'Test Step "' + testRunner.runContext.currentStep.name + '" done...';
    

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.