List of usage examples for com.amazonaws.auth.profile ProfileCredentialsProvider ProfileCredentialsProvider
public ProfileCredentialsProvider()
From source file:CreateUserFavoritesTable.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "UserFavorites"; try {/*from w w w.jav a 2 s. co m*/ System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }
From source file:AddUserInfo.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("UserInfo"); int UserID = 0; String FirstName = "Patrick"; String LastName = "Laflin"; String PhoneNumber = "(850)276-3816"; String StreetAddressLine1 = "118 E Lakeshore Drive"; String StreetAddressLine2 = "Unit B"; String City = "Panama City Beach"; String State = "FL"; int ZipCode = 32413; String EmailAddress = "pbl14@my.fsu.edu"; try {/*from ww w . j ava2 s . co m*/ System.out.println("Adding a new item..."); PutItemOutcome outcome = table.putItem(new Item().withPrimaryKey("UserID", UserID) .withString("First Name", FirstName).withString("Last Name", LastName) .withString("Phone Number", PhoneNumber).withString("Street Address Line 1", StreetAddressLine1) .withString("Street Address Line 2", StreetAddressLine2).withString("City", City) .withString("State", State).withNumber("Zip Code", ZipCode) .withString("Email Address", EmailAddress)); System.out.println("PutItem succeeded:\n" + outcome.getPutItemResult()); } catch (Exception e) { System.err.println("Unable to add item: " + UserID); System.err.println(e.getMessage()); } }
From source file:AWS.java
/** * Creates new form main/*from ww w . j ava 2 s . c om*/ */ public AWS() { AWSCredentials credentials = new ProfileCredentialsProvider().getCredentials(); String endPoint; Region region; endPoint = "https://ec2.eu-west-1.amazonaws.com"; region = Region.getRegion(Regions.EU_WEST_1); ec2client = new AmazonEC2Client(credentials); ec2client.setEndpoint(endPoint); ec2client.setRegion(region); initComponents(); }
From source file:AddUserRoutes.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("UserRoutes"); int UserID = 0; String Route1 = "NULL"; String Route2 = "NULL"; String Route3 = "NULL"; String Route4 = "NULL"; String Route5 = "NULL"; try {//from w ww .j a v a 2 s . co m System.out.println("Adding a new item..."); PutItemOutcome outcome = table.putItem(new Item().withPrimaryKey("UserID", UserID) .withString("Route 1", Route1).withString("Route 2", Route2).withString("Route 3", Route3) .withString("Route 4", Route4).withString("Route 5", Route5)); System.out.println("PutItem succeeded:\n" + outcome.getPutItemResult()); } catch (Exception e) { System.err.println("Unable to add item: " + UserID); System.err.println(e.getMessage()); } }
From source file:CreateUserInfoTable.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "UserInfo"; try {/*from ww w. j a va2 s. co m*/ System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }
From source file:SimpleQueueServiceMultiThread2.java
License:Open Source License
public static void main(String[] args) throws Exception { /*/*from w w w. ja v a 2s.c om*/ * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } //AmazonSQS sqs = new AmazonSQSClient(credentials,clientConfig); sqs = new AmazonSQSClient(credentials); Region apSouthEast1 = Region.getRegion(Regions.AP_SOUTHEAST_1); sqs.setRegion(apSouthEast1); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); //Define thread pool size ExecutorService executor = Executors.newFixedThreadPool(poolSize); //create a list to hold the Future object associated with Callable List<Future<Long>> list = new ArrayList<Future<Long>>(); //Create Callable instance Callable<Long> callable = new SimpleQueueServiceMultiThread2(); for (int i = 0; i < threadSize; i++) { //submit Callable tasks to be executed by thread pool Future<Long> future = executor.submit(callable); //add Future to the list, we can get return value using Future list.add(future); } for (Future<Long> fut : list) { try { // Future.get() waits for task to get completed System.out.println("Time difference : " + fut.get()); long timeDiff = fut.get().longValue(); totalTime = Long.valueOf(totalTime + timeDiff); if (timeDiff >= maxTime) { maxTime = timeDiff; } if (minTime == 0L && timeDiff >= minTime) { minTime = timeDiff; //}else if (timeDiff <= minTime && timeDiff != 0L) { } else if (timeDiff <= minTime) { minTime = timeDiff; } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } } if (totalTime >= 0L) { averageTime = totalTime / threadSize; } System.out.println("Total Time : " + Long.valueOf(totalTime).toString()); System.out.println("Max Time : " + Long.valueOf(maxTime).toString()); System.out.println("Min Time : " + Long.valueOf(minTime).toString()); System.out.println("Average Time : " + Long.valueOf(averageTime).toString()); //shut down the executor service now executor.shutdown(); }
From source file:AmazonKinesisApplicationSample.java
License:Open Source License
private static void init() { // Ensure the JVM will refresh the cached IP values of AWS resources (e.g. service endpoints). java.security.Security.setProperty("networkaddress.cache.ttl", "60"); /*//from ww w. j av a2 s . c o m * The ProfileCredentialsProvider will return your [haow2] * credential profile by reading from the credentials file located at * (/Users/Dawn/.aws/credentials). */ credentialsProvider = new ProfileCredentialsProvider(); try { credentialsProvider.getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (/Users/Dawn/.aws/credentials), and is in valid format.", e); } }
From source file:AddUserFavorites.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable("UserFavorites"); int UserID = 0; String Location1 = "NULL"; String Location2 = "NULL"; String Location3 = "NULL"; String Location4 = "NULL"; String Location5 = "NULL"; try {// ww w . ja v a2 s.c om System.out.println("Adding a new item..."); PutItemOutcome outcome = table .putItem(new Item().withPrimaryKey("UserID", UserID).withString("Location 1", Location1) .withString("Location 2", Location2).withString("Location 3", Location3) .withString("Location 4", Location4).withString("Location 5", Location5)); System.out.println("PutItem succeeded:\n" + outcome.getPutItemResult()); } catch (Exception e) { System.err.println("Unable to add item: " + UserID); System.err.println(e.getMessage()); } }
From source file:AbstractAmazonKinesisFirehoseDelivery.java
License:Open Source License
/** * Method to initialize the clients using the specified AWSCredentials. * * @param Exception//from w ww. j a va 2s .co m */ protected static void initClients() throws Exception { /* * The ProfileCredentialsProvider will return your [default] credential * profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } // S3 client s3Client = new AmazonS3Client(credentials); Region s3Region = RegionUtils.getRegion(s3RegionName); s3Client.setRegion(s3Region); // Firehose client firehoseClient = new AmazonKinesisFirehoseClient(credentials); firehoseClient.setRegion(RegionUtils.getRegion(firehoseRegion)); // IAM client iamClient = new AmazonIdentityManagementClient(credentials); iamClient.setRegion(RegionUtils.getRegion(iamRegion)); }
From source file:CreateUserRoutesTable.java
License:Open Source License
public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider()); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "UserRoutes"; try {//from w ww .j a v a 2 s. c om System.out.println("Attempting to create table; please wait..."); Table table = dynamoDB.createTable(tableName, Arrays.asList(new KeySchemaElement("UserID", KeyType.HASH)), //Partition key Arrays.asList(new AttributeDefinition("UserID", ScalarAttributeType.N)), new ProvisionedThroughput(10L, 10L)); table.waitForActive(); System.out.println("Success. Table status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Unable to create table: "); System.err.println(e.getMessage()); } }