Example usage for com.amazonaws AmazonServiceException getErrorCode

List of usage examples for com.amazonaws AmazonServiceException getErrorCode

Introduction

In this page you can find the example usage for com.amazonaws AmazonServiceException getErrorCode.

Prototype

public String getErrorCode() 

Source Link

Document

Returns the AWS error code represented by this exception.

Usage

From source file:AmazonKinesisFirehoseToRedshiftSample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();/*from   w  w  w.  j av  a 2  s  .  c  o  m*/

    try {
        // Create S3 bucket for DeliveryStream to deliver data
        createS3Bucket();

        // Create the DeliveryStream
        createDeliveryStream();

        // Print the list of delivery streams
        printDeliveryStreams();

        // Put records into DeliveryStream
        LOG.info("Putting records in DeliveryStream : " + deliveryStreamName + " via Put Record method.");
        putRecordIntoDeliveryStream();

        // Batch Put records into DeliveryStream
        LOG.info("Putting records in DeliveryStream : " + deliveryStreamName
                + " via Put Record Batch method. Now you can check your S3 bucket " + s3BucketName
                + " for the data delivered by DeliveryStream.");
        putRecordBatchIntoDeliveryStream();

        // Wait for some interval for the firehose to write data to redshift destination
        int waitTimeSecs = s3DestinationIntervalInSeconds == null ? DEFAULT_WAIT_INTERVAL_FOR_DATA_DELIVERY_SECS
                : s3DestinationIntervalInSeconds;
        waitForDataDelivery(waitTimeSecs);

        // Update the DeliveryStream and Put records into updated DeliveryStream, only if the flag is set
        if (enableUpdateDestination) {
            // Update the DeliveryStream
            updateDeliveryStream();

            // Wait for some interval to propagate the updated configuration options before ingesting data
            LOG.info("Waiting for few seconds to propagate the updated configuration options.");
            TimeUnit.SECONDS.sleep(60);

            // Put records into updated DeliveryStream.
            LOG.info("Putting records in updated DeliveryStream : " + deliveryStreamName
                    + " via Put Record method.");
            putRecordIntoDeliveryStream();

            // Batch Put records into updated DeliveryStream.
            LOG.info("Putting records in updated DeliveryStream : " + deliveryStreamName
                    + " via Put Record Batch method.");
            putRecordBatchIntoDeliveryStream();

            // Wait for some interval for the DeliveryStream to write data to redshift destination
            waitForDataDelivery(waitTimeSecs);
        }
    } catch (AmazonServiceException ase) {
        LOG.error("Caught Amazon Service Exception");
        LOG.error("Status Code " + ase.getErrorCode());
        LOG.error("Message: " + ase.getErrorMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.error("Caught Amazon Client Exception");
        LOG.error("Exception Message " + ace.getMessage(), ace);
    }
}

From source file:NYSELoad.java

License:Open Source License

private static void readAndLoad(String tableName, String nysePath) {
    try {/*from   w  w w.  j a v  a 2  s . c o m*/
        // Create table if it does not exist yet
        if (!Tables.doesTableExist(dynamoDB, tableName)) {
            System.out.println("Table " + tableName + " is does not exist");
        }

        File localInputFolder = new File(nysePath);
        File[] listOfDirectories = localInputFolder.listFiles();
        for (File dir : listOfDirectories) {
            if (dir.isDirectory()) {
                File[] files = dir.listFiles();
                for (File file : files) {
                    BufferedReader br = null;
                    if (file.getName().endsWith("csv")) {
                        // Add an item
                        String sCurrentLine;

                        try {
                            br = new BufferedReader(new FileReader(file));
                            while ((sCurrentLine = br.readLine()) != null) {
                                nyseParser.parse(sCurrentLine);
                                Map<String, AttributeValue> item = newItem(nyseParser);
                                putItem(tableName, item);
                            }
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with AWS, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:SimpleDBExample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    /*/*  ww  w  . j a  v  a  2  s. c  o  m*/
     * This credentials provider implementation loads your AWS credentials
     * from a properties file at the root of your classpath.
     *
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials
     */
    AmazonSimpleDB sdb = new AmazonSimpleDBClient(new ClasspathPropertiesFileCredentialsProvider());
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    sdb.setRegion(usWest2);

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SimpleDB");
    System.out.println("===========================================\n");

    try {
        // Create a domain
        String myDomain = "MyStore";
        System.out.println("Creating domain called " + myDomain + ".\n");
        sdb.createDomain(new CreateDomainRequest(myDomain));

        // List domains
        System.out.println("Listing all domains in your account:\n");
        for (String domainName : sdb.listDomains().getDomainNames()) {
            System.out.println("  " + domainName);
        }
        System.out.println();

        // Put data into a domain
        System.out.println("Putting data into " + myDomain + " domain.\n");
        sdb.batchPutAttributes(new BatchPutAttributesRequest(myDomain, createSampleData()));

        // Select data from a domain
        // Notice the use of backticks around the domain name in our select expression.
        String selectExpression = "select * from `" + myDomain + "` where Category = 'Clothes'";
        System.out.println("Selecting: " + selectExpression + "\n");
        SelectRequest selectRequest = new SelectRequest(selectExpression);
        for (Item item : sdb.select(selectRequest).getItems()) {
            System.out.println("  Item");
            System.out.println("    Name: " + item.getName());
            for (Attribute attribute : item.getAttributes()) {
                System.out.println("      Attribute");
                System.out.println("        Name:  " + attribute.getName());
                System.out.println("        Value: " + attribute.getValue());
            }
        }
        System.out.println();

        // Delete values from an attribute
        System.out.println("Deleting Blue attributes in Item_O3.\n");
        Attribute deleteValueAttribute = new Attribute("Color", "Blue");
        sdb.deleteAttributes(
                new DeleteAttributesRequest(myDomain, "Item_03").withAttributes(deleteValueAttribute));

        // Delete an attribute and all of its values
        System.out.println("Deleting attribute Year in Item_O3.\n");
        sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")
                .withAttributes(new Attribute().withName("Year")));

        // Replace an attribute
        System.out.println("Replacing Size of Item_03 with Medium.\n");
        List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
        replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true));
        sdb.putAttributes(new PutAttributesRequest(myDomain, "Item_03", replaceableAttributes));

        // Delete an item and all of its attributes
        System.out.println("Deleting Item_03.\n");
        sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03"));

        // Delete a domain
        System.out.println("Deleting " + myDomain + " domain.\n");
        sdb.deleteDomain(new DeleteDomainRequest(myDomain));
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SimpleDB, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with SimpleDB, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:S3Sample.java

License:Open Source License

public static void main2(String[] args) throws IOException {
    /*//w  w w.  j  a  v a  2s . c  om
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials
     */
    AmazonS3 s3 = new AmazonS3Client(
            new PropertiesCredentials(S3Sample.class.getResourceAsStream("AwsCredentials.properties")));

    //String bucketName = "my-first-s3-bucket-" + UUID.randomUUID();
    String bucketName = "ringtone_image";
    String key = "test";

    System.out.println("being...");
    System.out.println("size:");
    System.out.println("end.\n");

    try {
        /*
         * Create a new S3 bucket - Amazon S3 bucket names are globally unique,
         * so once a bucket name has been taken by any user, you can't create
         * another bucket with that same name.
         *
         * You can optionally specify a location for your bucket if you want to
         * keep your data closer to your applications or users.
                
        System.out.println("Creating bucket " + bucketName + "\n");
        s3.createBucket(bucketName);
         */

        /*
         * List the buckets in your account
                 
        System.out.println("Listing buckets");
        for (Bucket bucket : s3.listBuckets()) {
        System.out.println(" - " + bucket.getName());
        }
        System.out.println();
         */

        /*
         * Upload an object to your bucket - You can easily upload a file to
         * S3, or upload directly an InputStream if you know the length of
         * the data in the stream. You can also specify your own metadata
         * when uploading to S3, which allows you set a variety of options
         * like content-type and content-encoding, plus additional metadata
         * specific to your applications.
                
        System.out.println("Uploading a new object to S3 from a file\n");
        s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile()));         
        */

        /*
         * Download an object - When you download an object, you get all of
         * the object's metadata and a stream from which to read the contents.
         * It's important to read the contents of the stream as quickly as
         * possibly since the data is streamed directly from Amazon S3 and your
         * network connection will remain open until you read all the data or
         * close the input stream.
         *
         * GetObjectRequest also supports several other options, including
         * conditional downloading of objects based on modification times,
         * ETags, and selectively downloading a range of an object.
                
                
        System.out.println("Downloading an object");
        S3Object object = s3.getObject(new GetObjectRequest(bucketName, key));
        System.out.println("Content-Type: "  + object.getObjectMetadata().getContentType());
        displayTextInputStream(object.getObjectContent());
         */

        /*
         * List objects in your bucket by prefix - There are many options for
         * listing the objects in your bucket.  Keep in mind that buckets with
         * many objects might truncate their results when listing their objects,
         * so be sure to check if the returned object listing is truncated, and
         * use the AmazonS3.listNextBatchOfObjects(...) operation to retrieve
         * additional results.
                
                
                
        System.out.println("Listing objects");
                
        ObjectListing objectListing = s3.listObjects(new ListObjectsRequest()
            .withBucketName(bucketName)
            .withPrefix("My"));
                
                
        for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
        System.out.println(" - " + objectSummary.getKey() + "  " +
                           "(size = " + objectSummary.getSize() + ")");
                   
        }
        */

        /*
         * Delete an object - Unless versioning has been turned on for your bucket,
         * there is no way to undelete an object, so use caution when deleting objects.
                
                
        System.out.println("Deleting an object\n");
        s3.deleteObject(bucketName, key);
         */

        /*
         * Delete a bucket - A bucket must be completely empty before it can be
         * deleted, so remember to delete any objects from your buckets before
         * you try to delete them.
                
                
        System.out.println("Deleting bucket " + bucketName + "\n");
        s3.deleteBucket(bucketName);
         */
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon S3, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:GettingStartedApp.java

License:Open Source License

public static void main(String[] args) throws Exception {

    System.out.println("===========================================");
    System.out.println("Welcome to the AWS Java SDK!");
    System.out.println("===========================================");

    /*/*  ww  w . java2s .  c om*/
     * Amazon EC2
     *
     * The AWS EC2 client allows you to create, delete, and administer
     * instances programmatically.
     *
     * In this sample, we use an EC2 client to submit a Spot request,
     * wait for it to reach the active state, and then cancel and terminate
     * the associated instance.
     */
    try {
        // Setup the helper object that will perform all of the API calls.
        Requests requests = new Requests();

        // Submit all of the requests.
        requests.submitRequests();

        // Loop through all of the requests until all bids are in the active state
        // (or at least not in the open state).
        do {
            // Sleep for 60 seconds.
            Thread.sleep(SLEEP_CYCLE);
        } while (requests.areAnyOpen());

        // Cancel all requests and terminate all running instances.
        requests.cleanup();

    } catch (AmazonServiceException ase) {
        // Write out any exceptions that may have occurred.
        System.out.println("Caught Exception: " + ase.getMessage());
        System.out.println("Reponse Status Code: " + ase.getStatusCode());
        System.out.println("Error Code: " + ase.getErrorCode());
        System.out.println("Request ID: " + ase.getRequestId());
    }
}

From source file:whgHelper.java

License:Open Source License

public static void errorMessagesAse(AmazonServiceException ase) {
    System.out.println("Caught an AmazonServiceException, which means your request made it "
            + "to Amazon SQS, but was rejected with an error response for some reason.");
    System.out.println("Error Message:    " + ase.getMessage());
    System.out.println("HTTP Status Code: " + ase.getStatusCode());
    System.out.println("AWS Error Code:   " + ase.getErrorCode());
    System.out.println("Error Type:       " + ase.getErrorType());
    System.out.println("Request ID:       " + ase.getRequestId());
}

From source file:AwsSdkSample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    System.out.println("===========================================");
    System.out.println("Welcome to the AWS Java SDK!");
    System.out.println("===========================================");

    init();//from w w  w.  j  a  v a2 s .c  o  m

    try {
        /*
         * The Amazon EC2 client allows you to easily launch and configure
         * computing capacity in AWS datacenters.
         *
         * In this sample, we use the EC2 client to list the availability zones
         * in a region, and then list the instances running in those zones.
         */
        DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones();
        List<AvailabilityZone> availabilityZones = availabilityZonesResult.getAvailabilityZones();
        System.out.println("You have access to " + availabilityZones.size() + " availability zones:");
        for (AvailabilityZone zone : availabilityZones) {
            System.out.println(" - " + zone.getZoneName() + " (" + zone.getRegionName() + ")");
        }

        DescribeInstancesResult describeInstancesResult = ec2.describeInstances();
        Set<Instance> instances = new HashSet<Instance>();
        for (Reservation reservation : describeInstancesResult.getReservations()) {
            instances.addAll(reservation.getInstances());
        }

        System.out.println("You have " + instances.size() + " Amazon EC2 instance(s) running.");

        /*
         * The Amazon S3 client allows you to manage and configure buckets
         * and to upload and download data.
         *
         * In this sample, we use the S3 client to list all the buckets in
         * your account, and then iterate over the object metadata for all
         * objects in one bucket to calculate the total object count and
         * space usage for that one bucket. Note that this sample only
         * retrieves the object's metadata and doesn't actually download the
         * object's content.
         *
         * In addition to the low-level Amazon S3 client in the SDK, there
         * is also a high-level TransferManager API that provides
         * asynchronous management of uploads and downloads with an easy to
         * use API:
         *   http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/TransferManager.html
         */
        List<Bucket> buckets = s3.listBuckets();
        System.out.println("You have " + buckets.size() + " Amazon S3 bucket(s).");

        if (buckets.size() > 0) {
            Bucket bucket = buckets.get(0);

            long totalSize = 0;
            long totalItems = 0;
            /*
             * The S3Objects and S3Versions classes provide convenient APIs
             * for iterating over the contents of your buckets, without
             * having to manually deal with response pagination.
             */
            for (S3ObjectSummary objectSummary : S3Objects.inBucket(s3, bucket.getName())) {
                totalSize += objectSummary.getSize();
                totalItems++;
            }

            System.out.println("The bucket '" + bucket.getName() + "' contains " + totalItems + " objects "
                    + "with a total size of " + totalSize + " bytes.");
        }
    } catch (AmazonServiceException ase) {
        /*
         * AmazonServiceExceptions represent an error response from an AWS
         * services, i.e. your request made it to AWS, but the AWS service
         * either found it invalid or encountered an error trying to execute
         * it.
         */
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        /*
         * AmazonClientExceptions represent an error that occurred inside
         * the client on the local host, either while trying to send the
         * request to AWS or interpret the response. For example, if no
         * network connection is available, the client won't be able to
         * connect to AWS to execute a request and will throw an
         * AmazonClientException.
         */
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:AmazonKinesisSample.java

License:Open Source License

private static void waitForStreamToBecomeAvailable(String myStreamName) {

    System.out.println("Waiting for " + myStreamName + " to become ACTIVE...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        try {//from w w  w  .j a v a  2  s  .  com
            Thread.sleep(1000 * 20);
        } catch (InterruptedException e) {
            // Ignore interruption (doesn't impact stream creation)
        }
        try {
            DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest();
            describeStreamRequest.setStreamName(myStreamName);
            // ask for no more than 10 shards at a time -- this is an optional parameter
            describeStreamRequest.setLimit(10);
            DescribeStreamResult describeStreamResponse = kinesisClient.describeStream(describeStreamRequest);

            String streamStatus = describeStreamResponse.getStreamDescription().getStreamStatus();
            System.out.println("  - current state: " + streamStatus);
            if (streamStatus.equals("ACTIVE")) {
                return;
            }
        } catch (AmazonServiceException ase) {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false) {
                throw ase;
            }
            throw new RuntimeException("Stream " + myStreamName + " never went active");
        }
    }
}

From source file:SimpleDBWrite.java

License:Open Source License

public static void run(String searchItem) throws Exception {
    /*/*from w ww .ja  v a2 s .c  om*/
     * This credentials provider implementation loads your AWS credentials
     * from a properties file at the root of your classpath.
     *
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials
     */
    AmazonSimpleDB sdb = new AmazonSimpleDBClient(new ClasspathPropertiesFileCredentialsProvider());
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    sdb.setRegion(usWest2);

    try {
        // Create a domain
        String myDomain = "WanningStore";
        sdb.createDomain(new CreateDomainRequest(myDomain));

        // List domains
        //            System.out.println("Listing all domains in your account:\n");
        //            for (String domainName : sdb.listDomains().getDomainNames()) {
        //                System.out.println("  " + domainName);
        //            }
        //            System.out.println();

        // Put data into a domain
        System.out.println("Putting data into " + myDomain + " domain.\n");
        sdb.batchPutAttributes(new BatchPutAttributesRequest(myDomain, createData(searchItem)));

        //            // Delete values from an attribute
        //            System.out.println("Deleting Blue attributes in Item_O3.\n");
        //            Attribute deleteValueAttribute = new Attribute("Color", "Blue");
        //            sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")
        //                    .withAttributes(deleteValueAttribute));

        // Delete an attribute and all of its values
        //            System.out.println("Deleting attribute Year in Item_O3.\n");
        //            sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")
        //                    .withAttributes(new Attribute().withName("Year")));
        //
        //            // Replace an attribute
        //            System.out.println("Replacing Size of Item_03 with Medium.\n");
        //            List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
        //            replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true));
        //            sdb.putAttributes(new PutAttributesRequest(myDomain, "Item_03", replaceableAttributes));
        //
        //            // Delete an item and all of its attributes
        //            System.out.println("Deleting Item_03.\n");
        //            sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03"));
        //
        //            // Delete a domain
        //            System.out.println("Deleting " + myDomain + " domain.\n");
        //            sdb.deleteDomain(new DeleteDomainRequest(myDomain));
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SimpleDB, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with SimpleDB, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:SimpleQueueService.java

License:Open Source License

public static AmazonSQS push(HashMap<String, Integer> data, String Queuename) throws Exception {
    /*/*  w  ww.j a  v a 2 s  .  com*/
     * This credentials provider implementation loads your AWS credentials
     * from a properties file at the root of your classpath.
     *
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials
     */
    AmazonSQS sqs = new AmazonSQSClient(new ClasspathPropertiesFileCredentialsProvider());
    /*Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    sqs.setRegion(usWest2);
    */
    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SQS");
    System.out.println("===========================================\n");

    try {
        // Create a queue

        String myQueueUrl = null;

        System.out.println("Creating/ a new SQS queue called " + Queuename);
        CreateQueueRequest createQueueRequest = new CreateQueueRequest(Queuename);
        /**
            * the AWS API, the call to createQueue, shown in Listing 2, 
            * doesn't necessarily create a new queue every time. If the queue already exists, its handle is returned. In SQS, queues are just URLs; consequently, a queue handle is also just a URL. Note that in the AWS SDK API,
            *  the Queue URL is a String type and not the Java URL type
            * */

        myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl();
        QueuePath = myQueueUrl;
        System.out.println();

        // Send a message
        System.out.println("Sending a message to MyQueue.\n");
        sqs.sendMessage(new SendMessageRequest(myQueueUrl, data.toString()));

        return sqs;

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SQS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the Client encountered "
                + "a serious internal problem while trying to communicate with SQS, such as not "
                + "being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
    return sqs;
}