List of usage examples for com.amazonaws.auth PropertiesCredentials PropertiesCredentials
public PropertiesCredentials(InputStream inputStream) throws IOException
From source file:com.renatodelgaudio.awsupdate.EnvUtil.java
License:Open Source License
public static AmazonRoute53 buildRoute53(File aws) { AmazonRoute53 r53 = null;/* w w w . j a v a2 s . c o m*/ try { r53 = new AmazonRoute53Client(new PropertiesCredentials(aws)); } catch (Exception e) { log.error("Cannot build AmazonRouter53Client", e); throw new ConfigurationException(e.getMessage()); } return r53; }
From source file:com.renatodelgaudio.awsupdate.EnvUtil.java
License:Open Source License
public static AmazonEC2 buildEC2(File aws) { AmazonEC2 ec2 = null;// w w w .j ava 2s.com try { ec2 = new AmazonEC2Client(new PropertiesCredentials(aws)); } catch (Exception e) { log.error("Cannot build AmazonEC2Client", e); throw new ConfigurationException(e.getMessage()); } return ec2; }
From source file:com.shelfmap.simplequery.AWSTestBase.java
License:Apache License
public AmazonSimpleDB getAmazonSimpleDB() { try {/*from w ww. j a va 2 s .c o m*/ return new AmazonSimpleDBClient(new PropertiesCredentials(new File(getSecurityCredentialPath()))); } catch (IOException ex) { throw new IllegalStateException(ex); } catch (IllegalArgumentException ex) { throw new IllegalStateException(ex); } }
From source file:com.sjsu.faceit.example.S3Sample.java
License:Open Source License
public static void main(String[] args) throws IOException { /*/*from w w w. j a v a 2 s .c o m*/ * 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 */ System.out.println(new File(".").getAbsolutePath()); AmazonS3 s3 = new AmazonS3Client( new PropertiesCredentials(S3Sample.class.getResourceAsStream("AwsCredentials.properties"))); String bucketName = "my-first-s3-bucket-" + UUID.randomUUID(); String key = "MyObjectKey"; System.out.println("==========================================="); System.out.println("Getting Started with Amazon S3"); System.out.println("===========================================\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, "abc/" + key, new File("/Users/prayag/Desktop/2.jpg"))); /* * 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, "abc/" + 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() + ")"); } System.out.println(); /* * 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:com.stfciz.aws.ec2.data.EC2InstancesManager.java
/** * * @throws IOException/*from w ww .j a v a 2 s . c om*/ */ private void loadCredentials() throws IOException { File propertiesCredentialsFile = new File(CREDENTIALS_FILE); if (propertiesCredentialsFile.exists()) { this.credentials = new PropertiesCredentials(propertiesCredentialsFile); this.amazonEC2Client = new AmazonEC2Client(this.credentials); } }
From source file:com.yahoo.ycsb.db.DynamoDBClient.java
License:Open Source License
/** * Initialize any state for this DB. Called once per DB instance; there is * one DB instance per client thread./*w w w. ja va 2s . co m*/ */ public void init() throws DBException { // initialize DynamoDb driver & table. String debug = getProperties().getProperty("dynamodb.debug", null); if (null != debug && "true".equalsIgnoreCase(debug)) { logger.setLevel(Level.DEBUG); } String endpoint = getProperties().getProperty("dynamodb.endpoint", null); String credentialsFile = getProperties().getProperty("dynamodb.awsCredentialsFile", null); String primaryKey = getProperties().getProperty("dynamodb.primaryKey", null); String consistentReads = getProperties().getProperty("dynamodb.consistentReads", null); String connectMax = getProperties().getProperty("dynamodb.connectMax", null); if (null != connectMax) { this.maxConnects = Integer.parseInt(connectMax); } if (null != consistentReads && "true".equalsIgnoreCase(consistentReads)) { this.consistentRead = true; } if (null != endpoint) { this.endpoint = endpoint; } if (null == primaryKey || primaryKey.length() < 1) { String errMsg = "Missing primary key attribute name, cannot continue"; logger.error(errMsg); } try { AWSCredentials credentials = new PropertiesCredentials(new File(credentialsFile)); ClientConfiguration cconfig = new ClientConfiguration(); cconfig.setMaxConnections(maxConnects); dynamoDB = new AmazonDynamoDBClient(credentials, cconfig); dynamoDB.setEndpoint(this.endpoint); primaryKeyName = primaryKey; logger.info("dynamodb connection created with " + this.endpoint); } catch (Exception e1) { String errMsg = "DynamoDBClient.init(): Could not initialize DynamoDB client: " + e1.getMessage(); logger.error(errMsg); } }
From source file:com.yahoo.ycsb.db.MailAppDynamoDBClient.java
License:Open Source License
/** * Initialize any state for this DB. Called once per DB instance; there is * one DB instance per client thread.//www . j a va 2s .c om */ public void init() throws DBException { // initialize DynamoDb driver & table. String debug = getProperties().getProperty("dynamodb.debug", null); if (null != debug && "true".equalsIgnoreCase(debug)) { logger.setLevel(Level.DEBUG); } String endpoint = getProperties().getProperty("dynamodb.endpoint", null); String credentialsFile = getProperties().getProperty("dynamodb.awsCredentialsFile", null); String primaryKey = getProperties().getProperty("dynamodb.primaryKey", null); //range key support String rangeKey = getProperties().getProperty("dynamodb.rangeKey", "range"); this.rangeKeyName = rangeKey; String hashAndRangeKeyDelimiterProp = getProperties().getProperty("dynamodb.rangekeydelimiter", "_rangeKeyFollows_"); this.hashAndRangeKeyDelimiter = hashAndRangeKeyDelimiterProp; String consistentReads = getProperties().getProperty("dynamodb.consistentReads", null); String connectMax = getProperties().getProperty("dynamodb.connectMax", null); this.incrementTag = getProperties().getProperty("incrementtag", "#inc#"); this.decrementTag = getProperties().getProperty("decrementtag", "#dec#"); if (null != connectMax) { this.maxConnects = Integer.parseInt(connectMax); } if (null != consistentReads && "true".equalsIgnoreCase(consistentReads)) { this.consistentRead = true; } if (null != endpoint) { this.endpoint = endpoint; } if (null == primaryKey || primaryKey.length() < 1) { String errMsg = "Missing primary key attribute name, cannot continue"; logger.error(errMsg); } try { AWSCredentials credentials = new PropertiesCredentials(new File(credentialsFile)); ClientConfiguration cconfig = new ClientConfiguration(); cconfig.setMaxConnections(maxConnects); dynamoDB = new AmazonDynamoDBClient(credentials, cconfig); dynamoDB.setEndpoint(this.endpoint); primaryKeyName = primaryKey; logger.info("dynamodb connection created with " + this.endpoint); } catch (Exception e1) { String errMsg = "MailAppDynamoDBClient.init(): Could not initialize MailAppDynamoDB client: " + e1.getMessage(); logger.error(errMsg); } }
From source file:de.kopis.glacier.AbstractGlacierCommand.java
License:Open Source License
public AbstractGlacierCommand(final File credentials) throws IOException { this.credentials = new PropertiesCredentials(credentials); client = new AmazonGlacierClient(this.credentials); }
From source file:de.kopis.glacier.commands.AbstractCommand.java
License:Open Source License
public AbstractCommand(final URL endpoint, final File credentials) throws IOException { this.log = LogFactory.getLog(this.getClass()); if (credentials != null) { this.credentials = new PropertiesCredentials(credentials); this.client = new AmazonGlacierClient(this.credentials); this.sqs = new AmazonSQSClient(this.credentials); this.sns = new AmazonSNSClient(this.credentials); }/* ww w . j av a2s.c o m*/ if (endpoint != null) { this.setEndpoint(endpoint); } }
From source file:ec2_device_manager.CreateSecurityGroupApp.java
License:Open Source License
/** * @param args//from w w w . j a v a 2 s. com */ public static void main(String[] args) { // Retrieves the credentials from an AWSCredentials.properties file. AWSCredentials credentials = null; try { credentials = new PropertiesCredentials( CreateSecurityGroupApp.class.getResourceAsStream("AwsCredentials.properties")); } catch (IOException e1) { System.out.println("Credentials were not properly entered into AwsCredentials.properties."); System.out.println(e1.getMessage()); System.exit(-1); } // Create the AmazonEC2Client object so we can call various APIs. AmazonEC2 ec2 = new AmazonEC2Client(credentials); // Create a new security group. try { CreateSecurityGroupRequest securityGroupRequest = new CreateSecurityGroupRequest("GettingStartedGroup", "Getting Started Security Group"); ec2.createSecurityGroup(securityGroupRequest); } catch (AmazonServiceException ase) { // Likely this means that the group is already created, so ignore. System.out.println(ase.getMessage()); } String ipAddr = "0.0.0.0/0"; // Get the IP of the current host, so that we can limit the Security Group // by default to the ip range associated with your subnet. try { InetAddress addr = InetAddress.getLocalHost(); // Get IP Address ipAddr = addr.getHostAddress() + "/10"; } catch (UnknownHostException e) { } //System.exit(-1); // Create a range that you would like to populate. ArrayList<String> ipRanges = new ArrayList<String>(); ipRanges.add(ipAddr); // Open up port 23 for TCP traffic to the associated IP from above (e.g. ssh traffic). ArrayList<IpPermission> ipPermissions = new ArrayList<IpPermission>(); IpPermission ipPermission = new IpPermission(); ipPermission.setIpProtocol("tcp"); ipPermission.setFromPort(new Integer(22)); ipPermission.setToPort(new Integer(22)); ipPermission.setIpRanges(ipRanges); ipPermissions.add(ipPermission); try { // Authorize the ports to the used. AuthorizeSecurityGroupIngressRequest ingressRequest = new AuthorizeSecurityGroupIngressRequest( "GettingStartedGroup", ipPermissions); ec2.authorizeSecurityGroupIngress(ingressRequest); } catch (AmazonServiceException ase) { // Ignore because this likely means the zone has already been authorized. System.out.println(ase.getMessage()); } }