use of com.amazonaws.AmazonServiceException in project aws-doc-sdk-examples by awsdocs.
the class PutObject method main.
public static void main(String[] args) {
final String USAGE = "\n" + "To run this example, supply the name of an S3 bucket and a file to\n" + "upload to it.\n" + "\n" + "Ex: PutObject <bucketname> <filename>\n";
if (args.length < 2) {
System.out.println(USAGE);
System.exit(1);
}
String bucket_name = args[0];
String file_path = args[1];
String key_name = Paths.get(file_path).getFileName().toString();
System.out.format("Uploading %s to S3 bucket %s...\n", file_path, bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
s3.putObject(bucket_name, key_name, file_path);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
System.out.println("Done!");
}
use of com.amazonaws.AmazonServiceException in project SAGU by brianmcmichael.
the class AddVaultFrame method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jbtAdd) {
if ((jtfAddField.getText().trim().equals(""))) {
JOptionPane.showMessageDialog(null, "Enter the name of the vault to add.", "Error", JOptionPane.ERROR_MESSAGE);
} else {
try {
String vaultToAdd = jtfAddField.getText().trim();
//TODO Limit to valid chars
// Add the archive.
CreateVaultRequest cvreq = new CreateVaultRequest(vaultToAdd);
CreateVaultResult cvres = addClient.createVault(cvreq);
JOptionPane.showMessageDialog(null, "Added vault " + cvres.toString() + " successfully.", "Success", JOptionPane.INFORMATION_MESSAGE);
this.dispose();
} catch (AmazonServiceException k) {
JOptionPane.showMessageDialog(null, "The server returned an error.", "Error", JOptionPane.ERROR_MESSAGE);
} catch (AmazonClientException i) {
JOptionPane.showMessageDialog(null, "Client Error. Check that all fields are correct. Archive not added.", "Error", JOptionPane.ERROR_MESSAGE);
} catch (Exception j) {
JOptionPane.showMessageDialog(null, "Vault not Added. Unspecified Error.", "Error", JOptionPane.ERROR_MESSAGE);
}
jtfAddField.setText("");
jtfAddField.requestFocus();
}
} else if (e.getSource() == jbtBack) {
this.setVisible(false);
dispose();
} else {
JOptionPane.showMessageDialog(this, "Please choose a valid action.");
}
}
use of com.amazonaws.AmazonServiceException in project aws-doc-sdk-examples by awsdocs.
the class Query method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " Query <table> <read> <write>\n\n" + "Where:\n" + " table - the table to put the item in.\n" + " read - the new read capacity of the table.\n" + " write - the new write capacity of the table.\n\n" + "Example:\n" + " Query HelloTable 16 10\n";
if (args.length < 3) {
System.out.println(USAGE);
System.exit(1);
}
String table_name = args[0];
Long read_capacity = Long.parseLong(args[1]);
Long write_capacity = Long.parseLong(args[2]);
System.out.format("Updating %s with new provisioned throughput values\n", table_name);
System.out.format("Read capacity : %d\n", read_capacity);
System.out.format("Write capacity : %d\n", write_capacity);
ProvisionedThroughput table_throughput = new ProvisionedThroughput(read_capacity, write_capacity);
final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
try {
ddb.updateTable(table_name, table_throughput);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
System.out.println("Done!");
}
use of com.amazonaws.AmazonServiceException in project aws-doc-sdk-examples by awsdocs.
the class UpdateItem method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " UpdateItem <table> <name> <greeting>\n\n" + "Where:\n" + " table - the table to put the item in.\n" + " name - a name to update in the table. The name must exist,\n" + " or an error will result.\n" + "Additional fields can be specified by appending them to the end of the\n" + "input.\n\n" + "Examples:\n" + " UpdateItem SiteColors text default=000000 bold=b22222\n" + " UpdateItem SiteColors background default=eeeeee code=d3d3d3\n\n";
if (args.length < 3) {
System.out.println(USAGE);
System.exit(1);
}
String table_name = args[0];
String name = args[1];
ArrayList<String[]> extra_fields = new ArrayList<String[]>();
// any additional args (fields to add or update)?
for (int x = 2; x < args.length; x++) {
String[] fields = args[x].split("=", 2);
if (fields.length == 2) {
extra_fields.add(fields);
} else {
System.out.format("Invalid argument: %s\n", args[x]);
System.out.println(USAGE);
System.exit(1);
}
}
System.out.format("Updating \"%s\" in %s\n", name, table_name);
if (extra_fields.size() > 0) {
System.out.println("Additional fields:");
for (String[] field : extra_fields) {
System.out.format(" %s: %s\n", field[0], field[1]);
}
}
HashMap<String, AttributeValue> item_key = new HashMap<String, AttributeValue>();
item_key.put("Name", new AttributeValue(name));
HashMap<String, AttributeValueUpdate> updated_values = new HashMap<String, AttributeValueUpdate>();
for (String[] field : extra_fields) {
updated_values.put(field[0], new AttributeValueUpdate(new AttributeValue(field[1]), AttributeAction.PUT));
}
final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
try {
ddb.updateItem(table_name, item_key, updated_values);
} catch (ResourceNotFoundException e) {
System.err.println(e.getMessage());
System.exit(1);
} catch (AmazonServiceException e) {
System.err.println(e.getMessage());
System.exit(1);
}
System.out.println("Done!");
}
use of com.amazonaws.AmazonServiceException in project aws-doc-sdk-examples by awsdocs.
the class UpdateTable method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " UpdateTable <table> <read> <write>\n\n" + "Where:\n" + " table - the table to put the item in.\n" + " read - the new read capacity of the table.\n" + " write - the new write capacity of the table.\n\n" + "Example:\n" + " UpdateTable HelloTable 16 10\n";
if (args.length < 3) {
System.out.println(USAGE);
System.exit(1);
}
String table_name = args[0];
Long read_capacity = Long.parseLong(args[1]);
Long write_capacity = Long.parseLong(args[2]);
System.out.format("Updating %s with new provisioned throughput values\n", table_name);
System.out.format("Read capacity : %d\n", read_capacity);
System.out.format("Write capacity : %d\n", write_capacity);
ProvisionedThroughput table_throughput = new ProvisionedThroughput(read_capacity, write_capacity);
final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
try {
ddb.updateTable(table_name, table_throughput);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
System.out.println("Done!");
}
Aggregations