List of usage examples for com.amazonaws.auth.profile ProfileCredentialsProvider ProfileCredentialsProvider
public ProfileCredentialsProvider()
From source file:msv_upload_tool.FXMLDocumentController.java
private void uploadObject() { final Long max = file.length(); task = new Task<Void>() { @Override/*w ww .j ava 2 s. c om*/ protected Void call() { boolean doLoop = true; long total = 0; while (doLoop) { lock.readLock().lock(); try { total = totalBytes; } finally { lock.readLock().unlock(); } updateProgress(total, max); if (total == max) doLoop = false; try { Thread.sleep(50); //1000 milliseconds is one second. } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } updateProgress(-1, max); this.succeeded(); return null; } }; uploadProgress.progressProperty().bind(task.progressProperty()); task.setOnSucceeded(new EventHandler() { @Override public void handle(Event event) { label.setText(""); label2.setText(""); button.setDisable(true); button2.setDisable(false); } }); Thread th = new Thread(task); th.setDaemon(true); //disable the buttons button.setDisable(true); button2.setDisable(true); th.start(); String existingBucketName = "mstargeneralfiles"; String keyName = "duh/" + file.getName(); String filePath = file.getAbsolutePath(); TransferManager tm = new TransferManager(new ProfileCredentialsProvider()); // For more advanced uploads, you can create a request object // and supply additional request parameters (ex: progress listeners, // canned ACLs, etc.) PutObjectRequest request = new PutObjectRequest(existingBucketName, keyName, new File(filePath)); // You can ask the upload for its progress, or you can // add a ProgressListener to your request to receive notifications // when bytes are transferred. request.setGeneralProgressListener(new ProgressListener() { @Override public void progressChanged(ProgressEvent progressEvent) { System.out.println(progressEvent.toString()); lock.writeLock().lock(); try { totalBytes += progressEvent.getBytesTransferred(); } finally { lock.writeLock().unlock(); } } }); // TransferManager processes all transfers asynchronously, // so this call will return immediately. Upload upload = tm.upload(request); }
From source file:onl.area51.filesystem.s3.AbstractS3Action.java
License:Apache License
public AbstractS3Action(FileSystemIO delegate, Map<String, ?> env) { this.delegate = delegate; AWSCredentials credentials;// w ww . java 2s . com try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception ex) { 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.", ex); } s3 = new AmazonS3Client(credentials); Region region = Region.getRegion(Regions.EU_WEST_1); s3.setRegion(region); String n = FileSystemUtils.get(env, BUCKET_READ); if (n == null || n.trim().isEmpty()) { n = FileSystemUtils.get(env, BUCKET); } bucketName = Objects.requireNonNull(n, BUCKET + " or " + BUCKET_READ + " is not defined"); }
From source file:org.apache.flink.cloudsort.io.aws.AwsCurlInput.java
License:Apache License
@Override public void open(String objectName) throws IOException { Preconditions.checkNotNull(bucket);/*from www. j a v a 2s . c o m*/ AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider()); java.util.Date expiration = new java.util.Date(); long msec = expiration.getTime(); msec += 1000 * 60 * 60; // Add 1 hour. expiration.setTime(msec); GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucket, objectName); generatePresignedUrlRequest.setMethod(HttpMethod.GET); generatePresignedUrlRequest.setContentType(CONTENT_TYPE); generatePresignedUrlRequest.setExpiration(expiration); String url = s3Client.generatePresignedUrl(generatePresignedUrlRequest).toExternalForm(); downloader = new ProcessBuilder("curl", "-s", "-X", "GET", "-H", "Content-Type: " + CONTENT_TYPE, url) .redirectError(Redirect.INHERIT).start(); }
From source file:org.apache.flink.cloudsort.io.aws.AwsCurlOutput.java
License:Apache License
@Override public Process open(String filename, String taskId) throws IOException { Preconditions.checkNotNull(bucket);/*from ww w . j a v a 2 s.c o m*/ Preconditions.checkNotNull(prefix); Preconditions.checkNotNull(filename); Preconditions.checkNotNull(taskId); String objectName = prefix + taskId; AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider()); java.util.Date expiration = new java.util.Date(); long msec = expiration.getTime(); msec += 1000 * 60 * 60; // Add 1 hour. expiration.setTime(msec); GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucket, objectName); generatePresignedUrlRequest.setMethod(HttpMethod.PUT); generatePresignedUrlRequest.setContentType(CONTENT_TYPE); generatePresignedUrlRequest.setExpiration(expiration); String url = s3Client.generatePresignedUrl(generatePresignedUrlRequest).toExternalForm(); return new ProcessBuilder("curl", "-s", "--max-time", "60", "--retry", "1024", "-X", "PUT", "-H", "Content-Type: " + CONTENT_TYPE, "--data-binary", "@" + filename, url) .redirectError(Redirect.INHERIT).redirectOutput(Redirect.INHERIT).start(); }
From source file:org.apache.flink.cloudsort.io.aws.AwsInput.java
License:Apache License
@Override public List<InputSplit> list() { Preconditions.checkNotNull(bucket);//from ww w . j a v a2s . c o m Preconditions.checkNotNull(prefix); List<InputSplit> objectNames = new ArrayList<>(); // this will read credentials from user's home directory AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider()); final ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(bucket).withPrefix(prefix); ListObjectsV2Result result; int index = 0; do { result = s3client.listObjectsV2(req); for (S3ObjectSummary objectSummary : result.getObjectSummaries()) { String objectName = objectSummary.getKey(); long objectSize = objectSummary.getSize(); objectNames.add(new InputSplit(index++, objectName, objectSize)); } req.setContinuationToken(result.getNextContinuationToken()); } while (result.isTruncated()); return objectNames; }
From source file:org.apache.storm.kinesis.spout.CredentialsProviderChain.java
License:Apache License
public CredentialsProviderChain() { super(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider(), new ProfileCredentialsProvider()); }
From source file:org.ecocean.media.S3AssetStore.java
License:Open Source License
public AmazonS3 getS3Client() { if (s3Client != null) return s3Client; if ((config.getString("AWSAccessKeyId") != null) && (config.getString("AWSSecretAccessKey") != null)) { s3Client = new AmazonS3Client(new BasicAWSCredentials(config.getString("AWSAccessKeyId"), config.getString("AWSSecretAccessKey"))); } else { //we try the default credentials file s3Client = new AmazonS3Client(new ProfileCredentialsProvider()); }/*from ww w . jav a2 s . com*/ return s3Client; }
From source file:org.eluder.logback.ext.aws.core.AwsSupport.java
License:Open Source License
public AWSCredentialsProvider getCredentials(AWSCredentials credentials) { return new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new StaticCredentialsProvider(credentials == null ? new NullCredentials() : credentials), new ProfileCredentialsProvider(), new InstanceProfileCredentialsProvider()); }
From source file:org.force66.aws.utils.S3Utils.java
License:Apache License
public static Properties loadProperties(String bucketName, String key) throws IOException { Properties props = new Properties(); AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider()); S3Object s3object = s3Client.getObject(new GetObjectRequest(bucketName, key)); props.load(s3object.getObjectContent()); return props; }
From source file:org.freeeed.aws.SimpleQueueServiceSample.java
License:Apache License
public static void main(String[] args) throws Exception { /*/*w ww.j ava 2 s . co m*/ * 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); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sqs.setRegion(usWest2); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); try { // Create a queue System.out.println("Creating a new SQS queue called MyQueue.\n"); CreateQueueRequest createQueueRequest = new CreateQueueRequest("MyQueue"); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); // List queues System.out.println("Listing all queues in your account.\n"); // TODO restore System.out.println(); // Send a message System.out.println("Sending a message to MyQueue.\n"); sqs.sendMessage(new SendMessageRequest(myQueueUrl, "This is my message text.")); // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); for (Message message : messages) { System.out.println(message.toString()); } System.out.println(); // Delete a message System.out.println("Deleting a message.\n"); String messageReceiptHandle = messages.get(0).getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageReceiptHandle)); // Delete a queue System.out.println("Deleting the test queue.\n"); sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, 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 SQS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }