List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials
public BasicAWSCredentials(String accessKey, String secretKey)
From source file:ca.paullalonde.gocd.sns_plugin.executors.StageStatusRequestExecutor.java
License:Apache License
private AmazonSNS makeSns(PluginSettings pluginSettings) throws Exception { String region = pluginSettings.getRegion(); String awsAccessId = pluginSettings.getAwsAccessId(); String awsSecretId = pluginSettings.getAwsSecretAccessId(); AmazonSNSClientBuilder builder = AmazonSNSClientBuilder.standard(); if ((region != null) && !region.isEmpty()) { builder = builder.withRegion(region); }//from w w w . j av a2 s . c o m if ((awsAccessId != null) && !awsAccessId.isEmpty() && (awsSecretId != null) && !awsSecretId.isEmpty()) { BasicAWSCredentials awsCreds = new BasicAWSCredentials(awsAccessId, awsSecretId); builder = builder.withCredentials(new AWSStaticCredentialsProvider(awsCreds)); } return builder.build(); }
From source file:ca.pgon.amazons3masscontenttype.App.java
License:Apache License
public static void main(String[] args) { if (args.length != 4) { System.out.println("Usage: AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY BUCKET_NAME CONTENT_TYPE"); return;/* ww w .j a v a2s .co m*/ } // Get the parameters int i = 0; awsAccessKeyId = args[i++]; awsSecretAccessKey = args[i++]; bucketName = args[i++]; contentType = args[i++]; // Prepare service AWSCredentials awsCredentials = new BasicAWSCredentials(awsAccessKeyId, awsSecretAccessKey); amazonS3Client = new AmazonS3Client(awsCredentials); // Go through the first page ObjectListing objectListing = amazonS3Client.listObjects(bucketName); process(objectListing); // Go through the other pages while (objectListing.isTruncated()) { amazonS3Client.listNextBatchOfObjects(objectListing); process(objectListing); } System.out.println(); System.out.println("Processed " + count + " files"); }
From source file:ch.admin.isb.hermes5.persistence.s3.S3ServiceFactory.java
License:Apache License
public AmazonS3 getAmazonS3() { return "".equals(accessKey.getStringValue()) ? new AmazonS3Client() : new AmazonS3Client( new BasicAWSCredentials(accessKey.getStringValue(), secretKey.getStringValue())); }
From source file:ch.admin.isb.hermes5.tools.filebackup.FileBackup.java
License:Apache License
private AmazonSNS sns(String accessKey, String secretKey, String snsEndpoint) { AmazonSNS sns = accessKey == null || "".equals(accessKey) ? new AmazonSNSClient() : new AmazonSNSClient(new BasicAWSCredentials(accessKey, secretKey)); sns.setEndpoint(snsEndpoint);/*from www.j a v a2s. c o m*/ return sns; }
From source file:ch.admin.isb.hermes5.tools.filebackup.FileBackup.java
License:Apache License
private AmazonS3 s3(String accessKey, String secretKey, String s3Endpoint) { AmazonS3 s3 = accessKey == null || "".equals(accessKey) ? new AmazonS3Client() : new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey)); s3.setEndpoint(s3Endpoint);//from ww w.j a va2 s . c o m return s3; }
From source file:ch.entwine.weblounge.aws.AmazonWebServices.java
License:Open Source License
/** * {@inheritDoc}/*w w w . j a va2 s . c om*/ * * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary) */ @SuppressWarnings("rawtypes") public void updated(Dictionary properties) throws ConfigurationException { // Read the access key id accessKeyId = (String) properties.get(OPT_ACCESS_KEY_ID); if (StringUtils.isBlank(accessKeyId)) throw new ConfigurationException(OPT_ACCESS_KEY_ID, "not set"); logger.debug("Amazon access key id is '{}'", accessKeyId); // Read the access key secret accessKeySecret = (String) properties.get(OPT_ACCESS_KEY_SECRET); if (StringUtils.isBlank(accessKeySecret)) throw new ConfigurationException(OPT_ACCESS_KEY_SECRET, "not set"); logger.debug("Amazon access key secret is '{}'", accessKeySecret); // Create the credentials accessCredentials = new BasicAWSCredentials(accessKeyId, accessKeySecret); s3Serializer = new AmazonResourceSerializer(accessCredentials); }
From source file:ch.entwine.weblounge.maven.S3DeployMojo.java
License:Open Source License
/** * //ww w. jav a2 s . c om * {@inheritDoc} * * @see org.apache.maven.plugin.Mojo#execute() */ public void execute() throws MojoExecutionException, MojoFailureException { // Setup AWS S3 client AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); AmazonS3Client uploadClient = new AmazonS3Client(credentials); TransferManager transfers = new TransferManager(credentials); // Make sure key prefix does not start with a slash but has one at the // end if (keyPrefix.startsWith("/")) keyPrefix = keyPrefix.substring(1); if (!keyPrefix.endsWith("/")) keyPrefix = keyPrefix + "/"; // Keep track of how much data has been transferred long totalBytesTransferred = 0L; int items = 0; Queue<Upload> uploads = new LinkedBlockingQueue<Upload>(); try { // Check if S3 bucket exists getLog().debug("Checking whether bucket " + bucket + " exists"); if (!uploadClient.doesBucketExist(bucket)) { getLog().error("Desired bucket '" + bucket + "' does not exist!"); return; } getLog().debug("Collecting files to transfer from " + resources.getDirectory()); List<File> res = getResources(); for (File file : res) { // Make path of resource relative to resources directory String filename = file.getName(); String extension = FilenameUtils.getExtension(filename); String path = file.getPath().substring(resources.getDirectory().length()); String key = concat("/", keyPrefix, path).substring(1); // Delete old file version in bucket getLog().debug("Removing existing object at " + key); uploadClient.deleteObject(bucket, key); // Setup meta data ObjectMetadata meta = new ObjectMetadata(); meta.setCacheControl("public, max-age=" + String.valueOf(valid * 3600)); FileInputStream fis = null; GZIPOutputStream gzipos = null; final File fileToUpload; if (gzip && ("js".equals(extension) || "css".equals(extension))) { try { fis = new FileInputStream(file); File gzFile = File.createTempFile(file.getName(), null); gzipos = new GZIPOutputStream(new FileOutputStream(gzFile)); IOUtils.copy(fis, gzipos); fileToUpload = gzFile; meta.setContentEncoding("gzip"); if ("js".equals(extension)) meta.setContentType("text/javascript"); if ("css".equals(extension)) meta.setContentType("text/css"); } catch (FileNotFoundException e) { getLog().error(e); continue; } catch (IOException e) { getLog().error(e); continue; } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(gzipos); } } else { fileToUpload = file; } // Do a random check for existing errors before starting the next upload if (erroneousUpload != null) break; // Create put object request long bytesToTransfer = fileToUpload.length(); totalBytesTransferred += bytesToTransfer; PutObjectRequest request = new PutObjectRequest(bucket, key, fileToUpload); request.setProgressListener(new UploadListener(credentials, bucket, key, bytesToTransfer)); request.setMetadata(meta); // Schedule put object request getLog().info( "Uploading " + key + " (" + FileUtils.byteCountToDisplaySize((int) bytesToTransfer) + ")"); Upload upload = transfers.upload(request); uploads.add(upload); items++; } } catch (AmazonServiceException e) { getLog().error("Uploading resources failed: " + e.getMessage()); } catch (AmazonClientException e) { getLog().error("Uploading resources failed: " + e.getMessage()); } // Wait for uploads to be finished String currentUpload = null; try { Thread.sleep(1000); getLog().info("Waiting for " + uploads.size() + " uploads to finish..."); while (!uploads.isEmpty()) { Upload upload = uploads.poll(); currentUpload = upload.getDescription().substring("Uploading to ".length()); if (TransferState.InProgress.equals(upload.getState())) getLog().debug("Waiting for upload " + currentUpload + " to finish"); upload.waitForUploadResult(); } } catch (AmazonServiceException e) { throw new MojoExecutionException("Error while uploading " + currentUpload); } catch (AmazonClientException e) { throw new MojoExecutionException("Error while uploading " + currentUpload); } catch (InterruptedException e) { getLog().debug("Interrupted while waiting for upload to finish"); } // Check for errors that happened outside of the actual uploading if (erroneousUpload != null) { throw new MojoExecutionException("Error while uploading " + erroneousUpload); } getLog().info("Deployed " + items + " files (" + FileUtils.byteCountToDisplaySize((int) totalBytesTransferred) + ") to s3://" + bucket); }
From source file:ch.myniva.gradle.caching.s3.internal.AwsS3BuildCacheServiceFactory.java
License:Apache License
private AmazonS3 createS3Client(AwsS3BuildCache config) { AmazonS3 s3;/*from w ww. jav a2s . c om*/ try { AmazonS3ClientBuilder s3Builder = AmazonS3ClientBuilder.standard(); if (!isNullOrEmpty(config.getAwsAccessKeyId()) && !isNullOrEmpty(config.getAwsSecretKey())) { s3Builder.withCredentials(new AWSStaticCredentialsProvider( new BasicAWSCredentials(config.getAwsAccessKeyId(), config.getAwsSecretKey()))); } if (isNullOrEmpty(config.getEndpoint())) { s3Builder.withRegion(config.getRegion()); } else { s3Builder.withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegion())); } s3 = s3Builder.build(); } catch (SdkClientException e) { logger.debug("Error while building AWS S3 client: {}", e.getMessage()); throw new GradleException("Creation of S3 build cache failed; cannot create S3 client", e); } return s3; }
From source file:clojusc.aws.examples.swf.javaapp.GreeterMain.java
License:Open Source License
public static void main() throws Exception { ClientConfiguration config = new ClientConfiguration().withSocketTimeout(GreeterConstants.clientTimeout); AWSCredentials creds = new BasicAWSCredentials(System.getenv(GreeterConstants.accessKey), System.getenv(GreeterConstants.secretKey)); AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(creds, config); service.setEndpoint(GreeterConstants.endpoint); GreeterWorkflowClientExternalFactory factory = new GreeterWorkflowClientExternalFactoryImpl(service, GreeterConstants.domain);/*ww w . j a va2 s. c o m*/ GreeterWorkflowClientExternal greeter = factory.getClient(GreeterConstants.clientId); greeter.greet(); }
From source file:clojusc.aws.examples.swf.javaapp.GreeterWorker.java
License:Open Source License
public static void main() throws Exception { ClientConfiguration config = new ClientConfiguration().withSocketTimeout(GreeterConstants.clientTimeout); AWSCredentials creds = new BasicAWSCredentials(System.getenv(GreeterConstants.accessKey), System.getenv(GreeterConstants.secretKey)); AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(creds, config); service.setEndpoint(GreeterConstants.endpoint); ActivityWorker aw = new ActivityWorker(service, GreeterConstants.domain, GreeterConstants.taskListToPoll); aw.addActivitiesImplementation(new GreeterActivitiesImpl()); aw.start();//from w w w. jav a 2s. c o m WorkflowWorker wfw = new WorkflowWorker(service, GreeterConstants.domain, GreeterConstants.taskListToPoll); wfw.addWorkflowImplementationType(GreeterWorkflowImpl.class); wfw.start(); }