List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials
public BasicAWSCredentials(String accessKey, String secretKey)
From source file:englishcoffeedrinker.corpse.CORPSE.java
License:Open Source License
public static void main(String args[]) throws Exception { Properties properties = new Properties(); properties.load(new FileReader("corpse.properties")); String accessKey = properties.getProperty("accessKey"); String secretKey = properties.getProperty("secretKey"); Glacier glacier = new Glacier(AWSEndpoint.EU_WEST_1, new BasicAWSCredentials(accessKey, secretKey)); System.out.println(//from w w w. j a va 2 s . co m glacier.getEndpoint() + " Glacier contains " + humanReadableByteCount(glacier.getSizeInBytes()) + " in " + glacier.getNumberOfVaults() + " vaults"); for (Vault vault : glacier.getVaults()) { System.out.println(" " + vault.getName() + ": " + vault.getInventoryDate() + " " + humanReadableByteCount(vault.getSizeInBytes()) + " in " + vault.getNumberOfArchives() + " archives"); } System.out.println("Free Monthly Retrieval: " + humanReadableByteCount(glacier.getFreeMonthlyAllowance())); System.out.println("Free Daily Retrieval: " + humanReadableByteCount(glacier.getFreeDailyAllowance())); Vault v = Vault.fromJSON(new FileInputStream(new File("vault-inventory.json"))); System.out.println("\n" + v.getVaultARN() + ": " + v.getInventoryDate() + " contains " + humanReadableByteCount(v.getSizeInBytes()) + " in " + v.getNumberOfArchives()); XStream xstream = new XStream(); xstream.processAnnotations(Glacier.class); xstream.processAnnotations(RetrieveVaultInventory.class); System.out.println("\n" + xstream.toXML(glacier)); }
From source file:es.logongas.fpempresa.service.mail.impl.MailServiceImplAWS.java
License:Open Source License
@Override public void send(Mail mail) { try {//from w ww . ja v a 2s .co m Session session = Session.getDefaultInstance(new Properties()); Message message = JavaMailHelper.getMessage(mail, session); //Aqu es el proceso de envio AWSCredentials credentials = new BasicAWSCredentials(Config.getSetting("aws.accessKey"), Config.getSetting("aws.secretKey")); AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceAsyncClient(credentials); Region REGION = Region.getRegion(Regions.EU_WEST_1); client.setRegion(REGION); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); message.writeTo(outputStream); RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray())); SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage); client.sendRawEmail(rawEmailRequest); } catch (IllegalArgumentException | IOException | MessagingException ex) { throw new RuntimeException(ex); } }
From source file:eu.optimis.interopt.provider.aws.AmazonClient.java
License:Apache License
public AmazonEC2 getAmazonEC2Client() { log.info("Getting EC2 Client and selecting availability zone"); AmazonEC2 ec2 = new AmazonEC2Client(new BasicAWSCredentials(access_key, secret_key)); List<AvailabilityZone> availabilityZones = describeAZs("ec2.eu-west-1.amazonaws.com", ec2); if (!availabilityZones.isEmpty()) { availabilityZone = availabilityZones.get(0); log.info("Selected AZ: " + availabilityZone.getRegionName() + " - " + availabilityZone.getZoneName()); } else {/* ww w . j a v a 2 s. c o m*/ log.info("No zone found available in EU region, trying on other regions"); String[] endpoints = { "ec2.us-east-1.amazonaws.com", "ec2.us-west-2.amazonaws.com", "ec2.us-west-1.amazonaws.com", "ec2.ap-southeast-1.amazonaws.com", "ec2.ap-southeast-2.amazonaws.com", "ec2.ap-northeast-1.amazonaws.com", "ec2.sa-east-1.amazonaws.com" }; for (int i = 0; i < endpoints.length && availabilityZone != null; i++) { availabilityZones = describeAZs(endpoints[i], ec2); if (!availabilityZones.isEmpty()) { availabilityZone = availabilityZones.get(0); log.info("Selected AZ: " + availabilityZone.getRegionName() + " - " + availabilityZone.getZoneName()); } } } return ec2; }
From source file:eu.optimis.monitoring.amazoncollector.MeasurementsHelper.java
License:Apache License
public AmazonEC2 getAmazonEC2Client() { AmazonEC2 ec2 = new AmazonEC2Client(new BasicAWSCredentials(access_key, secret_key)); ec2.setEndpoint("ec2.eu-west-1.amazonaws.com"); return ec2;//from w ww . j a va 2s. c o m }
From source file:eu.optimis.monitoring.amazoncollector.MeasurementsHelper.java
License:Apache License
public AmazonCloudWatch getAmazonCloudWatchClient() { AmazonCloudWatch cw = new AmazonCloudWatchClient(new BasicAWSCredentials(access_key, secret_key)); cw.setEndpoint("monitoring.eu-west-1.amazonaws.com"); return cw;/*from w w w . ja va 2s .c om*/ }
From source file:eu.stratosphere.nephele.fs.s3.S3FileSystem.java
License:Apache License
/** * {@inheritDoc}//from www . j a va 2 s .c om */ @Override public void initialize(URI name) throws IOException { this.host = name.getHost(); if (this.host == null) { LOG.debug("Provided URI does not provide a host to connect to, using configuration..."); this.host = GlobalConfiguration.getString(S3_HOST_KEY, DEFAULT_S3_HOST); } this.port = name.getPort(); if (this.port == -1) { LOG.debug("Provided URI does not provide a port to connect to, using configuration..."); this.port = GlobalConfiguration.getInteger(S3_PORT_KEY, DEFAULT_S3_PORT); } final String userInfo = name.getUserInfo(); String awsAccessKey = null; String awsSecretKey = null; if (userInfo != null) { final String[] splits = userInfo.split(":"); if (splits.length > 1) { awsAccessKey = URLDecoder.decode(splits[0], URL_ENCODE_CHARACTER); awsSecretKey = URLDecoder.decode(splits[1], URL_ENCODE_CHARACTER); } } if (awsAccessKey == null) { LOG.debug("Provided URI does not provide an access key to Amazon S3, using configuration..."); awsAccessKey = GlobalConfiguration.getString(S3_ACCESS_KEY_KEY, null); if (awsAccessKey == null) { throw new IOException("Cannot determine access key to Amazon S3"); } } if (awsSecretKey == null) { LOG.debug("Provided URI does not provide a secret key to Amazon S3, using configuration..."); awsSecretKey = GlobalConfiguration.getString(S3_SECRET_KEY_KEY, null); if (awsSecretKey == null) { throw new IOException("Cannot determine secret key to Amazon S3"); } } final AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); this.s3Client = new AmazonS3Client(credentials); initializeDirectoryStructure(name); }
From source file:eu.stratosphere.nephele.instance.ec2.EC2ClientFactory.java
License:Apache License
/** * This factory method returns a the corresponding EC2Client object for the given credentials. * //from w w w.jav a 2 s. c o m * @param awsAccessId * @param awsSecretKey * @return the desired AmazonEC2Client. */ static synchronized AmazonEC2Client getEC2Client(final String awsAccessId, final String awsSecretKey) { if (awsAccessId == null) { throw new IllegalArgumentException("AWS access ID is null"); } if (awsSecretKey == null) { throw new IllegalArgumentException("AWS secret key is null"); } // Check if a client-object was already generated if (ec2clients.containsKey(awsAccessId)) { return ec2clients.get(awsAccessId); } // Create new EC2Client with given credentials final BasicAWSCredentials credentials = new BasicAWSCredentials(awsAccessId, awsSecretKey); final AmazonEC2Client client = new AmazonEC2Client(credentials); final String endpoint = GlobalConfiguration.getString("instancemanager.ec2.endpoint", "ec2.eu-west-1.amazonaws.com"); client.setEndpoint(endpoint); ec2clients.put(awsAccessId, client); return client; }
From source file:eu.stratosphere.runtime.fs.s3.S3FileSystem.java
License:Apache License
@Override public void initialize(URI name) throws IOException { this.host = name.getHost(); if (this.host == null) { LOG.debug("Provided URI does not provide a host to connect to, using configuration..."); this.host = GlobalConfiguration.getString(S3_HOST_KEY, DEFAULT_S3_HOST); }//from w w w . ja va 2s . c o m this.port = name.getPort(); if (this.port == -1) { LOG.debug("Provided URI does not provide a port to connect to, using configuration..."); this.port = GlobalConfiguration.getInteger(S3_PORT_KEY, DEFAULT_S3_PORT); } final String userInfo = name.getUserInfo(); String awsAccessKey = null; String awsSecretKey = null; if (userInfo != null) { final String[] splits = userInfo.split(":"); if (splits.length > 1) { awsAccessKey = URLDecoder.decode(splits[0], URL_ENCODE_CHARACTER); awsSecretKey = URLDecoder.decode(splits[1], URL_ENCODE_CHARACTER); } } if (awsAccessKey == null) { LOG.debug("Provided URI does not provide an access key to Amazon S3, using configuration..."); awsAccessKey = GlobalConfiguration.getString(S3_ACCESS_KEY_KEY, null); if (awsAccessKey == null) { throw new IOException("Cannot determine access key to Amazon S3"); } } if (awsSecretKey == null) { LOG.debug("Provided URI does not provide a secret key to Amazon S3, using configuration..."); awsSecretKey = GlobalConfiguration.getString(S3_SECRET_KEY_KEY, null); if (awsSecretKey == null) { throw new IOException("Cannot determine secret key to Amazon S3"); } } final AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); this.s3Client = new AmazonS3Client(credentials); initializeDirectoryStructure(name); }
From source file:fr.ens.biologie.genomique.eoulsan.data.protocols.S3DataProtocol.java
License:LGPL
/** * Get the AmazonS3 object./*from w w w. ja v a2 s .c o m*/ * @return an AmazonS3 */ private AmazonS3 getS3() { if (this.s3 == null) { final Settings settings = EoulsanRuntime.getSettings(); this.s3 = new AmazonS3Client( new BasicAWSCredentials(settings.getAWSAccessKey(), settings.getAWSSecretKey())); getLogger().info("AWS S3 account owner: " + this.s3.getS3AccountOwner()); this.tx = new TransferManager(this.s3); } return this.s3; }
From source file:fr.ens.biologie.genomique.eoulsan.util.cloud.AWSElasticMapReduceJob.java
License:LGPL
/** * Run the job./*w w w . j a v a 2 s . c o m*/ * @return a the JobFlowId of the job */ public String runJob() { // Get the credentials final AWSCredentials credentials = new BasicAWSCredentials(this.AWSAccessKey, this.AWSSecretKey); // Create the Amazon Elastic MapReduce object this.elasticMapReduceClient = new AmazonElasticMapReduceClient(credentials); // Set the end point this.elasticMapReduceClient.setEndpoint(this.endpoint); this.runFlowResult = this.elasticMapReduceClient.runJobFlow(this.runFlowRequest); return this.runFlowResult.getJobFlowId(); }