List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials
public BasicAWSCredentials(String accessKey, String secretKey)
From source file:com.dongli.model.MyAWSStorage.java
License:Open Source License
private MyAWSStorage() { myCredentials = new BasicAWSCredentials(MyConfiguration.getInstance().accessKey, MyConfiguration.getInstance().secretKey); s3client = new AmazonS3Client(myCredentials); }
From source file:com.dtolabs.rundeck.plugin.resources.ec2.EC2ResourceModelSource.java
License:Apache License
public EC2ResourceModelSource(final Properties configuration) { this.accessKey = configuration.getProperty(EC2ResourceModelSourceFactory.ACCESS_KEY); this.secretKey = configuration.getProperty(EC2ResourceModelSourceFactory.SECRET_KEY); this.endpoint = configuration.getProperty(EC2ResourceModelSourceFactory.ENDPOINT); this.httpProxyHost = configuration.getProperty(EC2ResourceModelSourceFactory.HTTP_PROXY_HOST); int proxyPort = 80; final String proxyPortStr = configuration.getProperty(EC2ResourceModelSourceFactory.HTTP_PROXY_PORT); if (null != proxyPortStr && !"".equals(proxyPortStr)) { try {//from www .j ava2 s . co m proxyPort = Integer.parseInt(proxyPortStr); } catch (NumberFormatException e) { logger.warn(EC2ResourceModelSourceFactory.HTTP_PROXY_PORT + " value is not valid: " + proxyPortStr); } } this.httpProxyPort = proxyPort; this.httpProxyUser = configuration.getProperty(EC2ResourceModelSourceFactory.HTTP_PROXY_USER); this.httpProxyPass = configuration.getProperty(EC2ResourceModelSourceFactory.HTTP_PROXY_PASS); this.filterParams = configuration.getProperty(EC2ResourceModelSourceFactory.FILTER_PARAMS); this.mappingParams = configuration.getProperty(EC2ResourceModelSourceFactory.MAPPING_PARAMS); final String mappingFilePath = configuration.getProperty(EC2ResourceModelSourceFactory.MAPPING_FILE); if (null != mappingFilePath) { mappingFile = new File(mappingFilePath); } int refreshSecs = 30; final String refreshStr = configuration.getProperty(EC2ResourceModelSourceFactory.REFRESH_INTERVAL); if (null != refreshStr && !"".equals(refreshStr)) { try { refreshSecs = Integer.parseInt(refreshStr); } catch (NumberFormatException e) { logger.warn(EC2ResourceModelSourceFactory.REFRESH_INTERVAL + " value is not valid: " + refreshStr); } } refreshInterval = refreshSecs * 1000; if (configuration.containsKey(EC2ResourceModelSourceFactory.USE_DEFAULT_MAPPING)) { useDefaultMapping = Boolean .parseBoolean(configuration.getProperty(EC2ResourceModelSourceFactory.USE_DEFAULT_MAPPING)); } if (configuration.containsKey(EC2ResourceModelSourceFactory.RUNNING_ONLY)) { runningOnly = Boolean .parseBoolean(configuration.getProperty(EC2ResourceModelSourceFactory.RUNNING_ONLY)); } if (null != accessKey && null != secretKey) { credentials = new BasicAWSCredentials(accessKey.trim(), secretKey.trim()); assumeRoleArn = null; } else { assumeRoleArn = configuration.getProperty(EC2ResourceModelSourceFactory.ROLE_ARN); } if (null != httpProxyHost && !"".equals(httpProxyHost)) { clientConfiguration.setProxyHost(httpProxyHost); clientConfiguration.setProxyPort(httpProxyPort); clientConfiguration.setProxyUsername(httpProxyUser); clientConfiguration.setProxyPassword(httpProxyPass); } initialize(); }
From source file:com.duboisproject.rushhour.Application.java
License:Open Source License
@Override public void onCreate() { String accessKey = getString(R.string.access_key); String secretKey = getString(R.string.secret_key); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); sdbInterface = new SdbInterface(credentials); toaster = new Toaster(); }
From source file:com.duff.timetracker.simpledb.SimpleDB.java
License:Open Source License
public static AmazonSimpleDBClient getInstance() { if (mSdbClient == null) { if (!PropertyLoader.getInstance().hasCredentials()) { throw new RuntimeException("Cant find credentials!!!!!"); }//from w ww. ja va 2s . c o m AWSCredentials credentials = new BasicAWSCredentials(PropertyLoader.getInstance().getAccessKey(), PropertyLoader.getInstance().getSecretKey()); mSdbClient = new AmazonSimpleDBClient(credentials); } return mSdbClient; }
From source file:com.dushyant.flume.sink.aws.sqs.BasicSQSMsgSender.java
License:Apache License
public BasicSQSMsgSender(String sqsUrl, String region, String awsAccessKey, String awsSecretKey) { this.sqsUrl = sqsUrl; this.region = region; this.awsAccessKey = awsAccessKey; this.awsSecretKey = awsSecretKey; AmazonSQS sqs = null;/* w w w .j a v a2 s .c o m*/ if (StringUtils.isBlank(awsAccessKey) || StringUtils.isBlank(awsSecretKey)) { LOG.warn( "Either awsAccessKey or awsSecretKey not specified. Will use DefaultAWSCredentialsProviderChain " + "to look for AWS credentials."); sqs = new AmazonSQSClient(); } else { sqs = new AmazonSQSClient(new BasicAWSCredentials(this.awsAccessKey, this.awsSecretKey)); } Region sqsRegion = Region.getRegion(Regions.fromName(this.region)); sqs.setRegion(sqsRegion); this.amazonSQS = sqs; }
From source file:com.dushyant.flume.sink.aws.sqs.BatchSQSMsgSender.java
License:Apache License
public BatchSQSMsgSender(String sqsUrl, String region, String awsAccessKey, String awsSecretKey, int batchSize, long maxMessageSize) { this.sqsUrl = sqsUrl; this.region = region; this.awsAccessKey = awsAccessKey; this.awsSecretKey = awsSecretKey; AmazonSQS sqs = null;//from w ww.java 2 s .co m if (StringUtils.isBlank(awsAccessKey) || StringUtils.isBlank(awsSecretKey)) { LOG.warn( "Either awsAccessKey or awsSecretKey not specified. Will use DefaultAWSCredentialsProviderChain " + "to look for AWS credentials."); sqs = new AmazonSQSClient(); } else { sqs = new AmazonSQSClient(new BasicAWSCredentials(this.awsAccessKey, this.awsSecretKey)); } Region sqsRegion = Region.getRegion(Regions.fromName(this.region)); sqs.setRegion(sqsRegion); this.batchSize = batchSize; this.maxMessageSize = maxMessageSize; this.amazonSQS = sqs; }
From source file:com.dustindoloff.s3websitedeploy.Main.java
License:Apache License
public static void main(final String[] args) { final Options options = buildOptions(); final CommandLineParser parser = new DefaultParser(); final CommandLine commandLine; try {/*from w w w . j a v a2s . c om*/ commandLine = parser.parse(options, args); } catch (final ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp("s3WebsiteDeploy", options); System.exit(1); return; } final File websiteZip = new File(commandLine.getOptionValue(ARG_WEBSITE_ZIP)); final String s3Bucket = commandLine.getOptionValue(ARG_BUCKET); final String awsAccessKey = commandLine.getOptionValue(ARG_AWS_ACCESS_KEY); final String awsSecretKey = commandLine.getOptionValue(ARG_AWS_SECRET_KEY); final ZipFile zipFile = getAsValidZip(websiteZip); if (zipFile == null) { System.out.println("Invalid zip file passed in"); System.exit(2); return; } System.out.println("Running S3 Website Deploy"); final AmazonS3 s3Client = new AmazonS3Client(new BasicAWSCredentials(awsAccessKey, awsSecretKey)); final Region bucketRegion = getBucketRegion(s3Client, s3Bucket); if (bucketRegion == null) { System.out.println("Unable to get the region for the bucket."); System.exit(3); return; } s3Client.setRegion(bucketRegion); if (!emptyBucket(s3Client, s3Bucket)) { System.out.println("Unable to upload to empty bucket."); System.exit(4); return; } if (!upload(s3Client, s3Bucket, zipFile)) { System.out.println("Unable to upload to S3."); System.exit(5); return; } System.out.println("Deployment Complete"); }
From source file:com.dxc.temp.SimpleProducerConsumer.java
License:Open Source License
public static void main(String[] args) throws InterruptedException { int argIndex = 0; final String accessKey = args[argIndex++]; final String secretKey = args[argIndex++]; final AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); final String endpoint = args[argIndex++]; final String queueName = args[argIndex++]; final int producerCount = Integer.parseInt(args[argIndex++]); final int consumerCount = Integer.parseInt(args[argIndex++]); final int batchSize = Integer.parseInt(args[argIndex++]); final int messageSizeByte = Integer.parseInt(args[argIndex++]); final int runTimeMinutes = Integer.parseInt(args[argIndex++]); // configure the SQS client with enough connections for all producer and // consumer threads AmazonSQS sqsClient = new AmazonSQSClient(credentials, new ClientConfiguration().withMaxConnections(producerCount + consumerCount)); sqsClient.setEndpoint(endpoint);//from w ww .j av a2s. c om String queueUrl = sqsClient.getQueueUrl(new GetQueueUrlRequest(queueName)).getQueueUrl(); // the flag to stop producer, consumer, and monitor threads AtomicBoolean stop = new AtomicBoolean(false); // start the producers final AtomicInteger producedCount = new AtomicInteger(); Thread[] producers = new Thread[producerCount]; for (int i = 0; i < producerCount; i++) { if (batchSize == 1) producers[i] = new Producer(sqsClient, queueUrl, messageSizeByte, producedCount, stop); else producers[i] = new BatchProducer(sqsClient, queueUrl, batchSize, messageSizeByte, producedCount, stop); producers[i].start(); } // start the consumers final AtomicInteger consumedCount = new AtomicInteger(); Thread[] consumers = new Thread[consumerCount]; for (int i = 0; i < consumerCount; i++) { if (batchSize == 1) consumers[i] = new Consumer(sqsClient, queueUrl, consumedCount, stop); else consumers[i] = new BatchConsumer(sqsClient, queueUrl, batchSize, consumedCount, stop); consumers[i].start(); } // start the monitor (thread) Thread monitor = new Monitor(producedCount, consumedCount, stop); monitor.start(); // wait for the specified amount of time then stop Thread.sleep(TimeUnit.MINUTES.toMillis(Math.min(runTimeMinutes, MAX_RUNTIME_MINUTES))); stop.set(true); // join all threads for (int i = 0; i < producerCount; i++) producers[i].join(); for (int i = 0; i < consumerCount; i++) consumers[i].join(); monitor.interrupt(); monitor.join(); }
From source file:com.dynamo.DynamoData.java
License:Open Source License
public void init() throws Exception { AWSCredentials credentials = null;/*from w ww .j a va2 s . co m*/ try { credentials = new BasicAWSCredentials("AKIAI6QKTRAQE7MXQOIQ", "wIG6u1yI5ZaseeJbvYSUmD98qelIJNSCVBzt5k2q"); } 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 (C:\\Users\\bssan_000\\.aws\\credentials), and is in valid format.", e); } dynamoDB = new AmazonDynamoDBClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDB.setRegion(usWest2); }
From source file:com.easarrive.aws.plugins.common.service.impl.SimpleProducerConsumer.java
License:Open Source License
public static void main(String[] args) throws InterruptedException { final AWSCredentials credentials = new BasicAWSCredentials("AKIAIDPJMKK4UHLE3OVA", "A+cn+TT3tUs6xbto5k1IKkWwPLBq995aOkqKxZNY"); final String endpoint = "sqs.us-west-2.amazonaws.com"; final String queueName = "image"; final int producerCount = 10; final int consumerCount = 3; final int batchSize = 3; final int messageSizeByte = 10000; final int runTimeMinutes = 100; // configure the SQS client with enough connections for all producer and // consumer threads AmazonSQS sqsClient = new AmazonSQSClient(credentials, new ClientConfiguration().withMaxConnections(producerCount + consumerCount)); sqsClient.setEndpoint(endpoint);/*w w w . j av a 2 s . c o m*/ String queueUrl = sqsClient.getQueueUrl(new GetQueueUrlRequest(queueName)).getQueueUrl(); // the flag to stop producer, consumer, and monitor threads AtomicBoolean stop = new AtomicBoolean(false); // start the producers final AtomicInteger producedCount = new AtomicInteger(); Thread[] producers = new Thread[producerCount]; for (int i = 0; i < producerCount; i++) { producers[i] = new BatchProducer(sqsClient, queueUrl, batchSize, messageSizeByte, producedCount, stop); producers[i].start(); } // start the consumers final AtomicInteger consumedCount = new AtomicInteger(); Thread[] consumers = new Thread[consumerCount]; for (int i = 0; i < consumerCount; i++) { consumers[i] = new BatchConsumer(sqsClient, queueUrl, batchSize, consumedCount, stop); consumers[i].start(); } // start the monitor (thread) Thread monitor = new Monitor(producedCount, consumedCount, stop); monitor.start(); // wait for the specified amount of time then stop Thread.sleep(TimeUnit.MINUTES.toMillis(Math.min(runTimeMinutes, MAX_RUNTIME_MINUTES))); stop.set(true); // join all threads for (int i = 0; i < producerCount; i++) producers[i].join(); for (int i = 0; i < consumerCount; i++) consumers[i].join(); monitor.interrupt(); monitor.join(); }