List of usage examples for com.amazonaws.auth.profile ProfileCredentialsProvider ProfileCredentialsProvider
public ProfileCredentialsProvider(String profileName)
From source file:org.apache.heron.uploader.s3.S3Uploader.java
License:Apache License
@Override public void initialize(Config config) { bucket = S3Context.bucket(config); String accessKey = S3Context.accessKey(config); String accessSecret = S3Context.secretKey(config); String awsProfile = S3Context.awsProfile(config); String proxy = S3Context.proxyUri(config); String endpoint = S3Context.uri(config); String customRegion = S3Context.region(config); AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard(); if (Strings.isNullOrEmpty(bucket)) { throw new RuntimeException("Missing heron.uploader.s3.bucket config value"); }/*ww w . j av a 2 s . c o m*/ // If an accessKey is specified, use it. Otherwise check if an aws profile // is specified. If neither was set just use the DefaultAWSCredentialsProviderChain // by not specifying a CredentialsProvider. if (!Strings.isNullOrEmpty(accessKey) || !Strings.isNullOrEmpty(accessSecret)) { if (!Strings.isNullOrEmpty(awsProfile)) { throw new RuntimeException("Please provide access_key/secret_key " + "or aws_profile, not both."); } if (Strings.isNullOrEmpty(accessKey)) { throw new RuntimeException("Missing heron.uploader.s3.access_key config value"); } if (Strings.isNullOrEmpty(accessSecret)) { throw new RuntimeException("Missing heron.uploader.s3.secret_key config value"); } builder.setCredentials( new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, accessSecret))); } else if (!Strings.isNullOrEmpty(awsProfile)) { builder.setCredentials(new ProfileCredentialsProvider(awsProfile)); } if (!Strings.isNullOrEmpty(proxy)) { URI proxyUri; try { proxyUri = new URI(proxy); } catch (URISyntaxException e) { throw new RuntimeException("Invalid heron.uploader.s3.proxy_uri config value: " + proxy, e); } ClientConfiguration clientCfg = new ClientConfiguration(); clientCfg.withProtocol(Protocol.HTTPS).withProxyHost(proxyUri.getHost()) .withProxyPort(proxyUri.getPort()); if (!Strings.isNullOrEmpty(proxyUri.getUserInfo())) { String[] info = proxyUri.getUserInfo().split(":", 2); clientCfg.setProxyUsername(info[0]); if (info.length > 1) { clientCfg.setProxyPassword(info[1]); } } builder.setClientConfiguration(clientCfg); } s3Client = builder.withRegion(customRegion).withPathStyleAccessEnabled(true) .withChunkedEncodingDisabled(true).withPayloadSigningEnabled(true).build(); if (!Strings.isNullOrEmpty(endpoint)) { s3Client.setEndpoint(endpoint); } final String topologyName = Context.topologyName(config); final String topologyPackageLocation = Context.topologyPackageFile(config); pathPrefix = S3Context.pathPrefix(config); packageFileHandler = new File(topologyPackageLocation); // The path the packaged topology will be uploaded to remoteFilePath = generateS3Path(pathPrefix, topologyName, packageFileHandler.getName()); // Generate the location of the backup file incase we need to revert the deploy previousVersionFilePath = generateS3Path(pathPrefix, topologyName, "previous_" + packageFileHandler.getName()); }
From source file:org.apache.nifi.processors.aws.credentials.provider.factory.strategies.NamedProfileCredentialsStrategy.java
License:Apache License
@Override public AWSCredentialsProvider getCredentialsProvider(Map<PropertyDescriptor, String> properties) { String profileName = properties.get(CredentialPropertyDescriptors.PROFILE_NAME); return new ProfileCredentialsProvider(profileName); }
From source file:org.kmbmicro.chatwebsocket.DbString.java
public static void init() { try {/*w w w . ja v a2 s .co m*/ credentials = new ProfileCredentialsProvider("default").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 (/Users/sandiwibowo/.aws/credentials), and is in valid format.", e); } AmazonDynamoDBClient dynamoDBAWS = new AmazonDynamoDBClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDBAWS.setRegion(usWest2); dynamoDB = new DynamoDB(dynamoDBAWS); }
From source file:org.xmlsh.aws.gradle.AwsPluginExtension.java
License:BSD License
public AWSCredentialsProvider newCredentialsProvider(String profileName) { return new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), Strings.isNullOrEmpty(profileName) == false ? new ProfileCredentialsProvider(profileName) : EMPTY, new ProfileCredentialsProvider(this.profileName), new InstanceProfileCredentialsProvider()); }
From source file:oulib.aws.Main.java
public static void main(String[] args) { try {/*from w w w. jav a 2 s . c om*/ AWSCredentials credentials = null; AmazonS3 s3Client = null; // args = new String[4]; // args[0] = "ul-bagit"; // args[1] = "ul-ir-workspace"; // args[2] = "Borelli_1680-1681"; // args[3] = "6"; try { credentials = new ProfileCredentialsProvider("default").getCredentials(); } catch (Exception e) { String access_key_id = null; String secret_key_id = null; String credentialInfo = AwsUtil.getAwsCredentials(); ObjectMapper mapper = new ObjectMapper(); Map<String, String> credentialInfoMap = new HashMap<>(); credentialInfoMap = mapper.readValue(credentialInfo, HashMap.class); for (String key : credentialInfoMap.keySet()) { if ("AccessKeyId".equals(key)) { access_key_id = credentialInfoMap.get(key); } else if ("SecretAccessKey".equals(key)) { secret_key_id = credentialInfoMap.get(key); } } // System.out.println("access_key_id = "+access_key_id+" access_key_id = "+access_key_id); if (null != access_key_id && null != secret_key_id) { credentials = new BasicAWSCredentials(access_key_id, secret_key_id); // s3Client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCreds)).build(); } else { throw new AmazonClientException("Cannot load the credentials from the credential information. " + "Please make sure that your credentials file is at the correct, and is in valid format.", e); } } ClientConfiguration config = new ClientConfiguration(); config.setConnectionTimeout(250000); config.setSocketTimeout(50000); s3Client = new AmazonS3Client(credentials, config); Region usEast = Region.getRegion(Regions.US_EAST_1); s3Client.setRegion(usEast); String bookName = args[2]; S3BookInfo bookInfo = new S3BookInfo(); bookInfo.setBookName(bookName); bookInfo.setBucketSourceName(args[0]); bookInfo.setBucketTargetName(args[1]); bookInfo.setCompressionSize(15000000); // *** Generate metadadta ***** // S3Util.copyS3ObjectTiffMetadata(s3client, "ul-bagit", "ul-ir-workspace", "Zuniga_1591/data/004.tif", "Zuniga_1591/data/004.tif"); // S3Util.copyS3ObjectTiffMetadata(s3client, "ul-bagit", "ul-ir-workspace", "Zuniga_1591/data/004.tif", "Zuniga_1591/data/004-20.tif"); // S3Util.copyS3ObjectTiffMetadata(s3client, "ul-bagit", "ul-ir-workspace", "Zuniga_1591/data/004.tif", "Zuniga_1591/data/004-50.tif"); // *** Generate small tiffs ***** Integer threadMaxCount = 0; try { threadMaxCount = Integer.valueOf(args[3]); } catch (Exception ex) { ex.printStackTrace();//logger.error("Cannot parse the thread count! "+ex.getMessage()); return; } System.out.println( "arg0 = " + args[0] + " arg1 = " + args[1] + " arg2 = " + args[2] + " arg3 = " + args[3]); ExecutorService executor = Executors.newFixedThreadPool(threadMaxCount); List<String> tiffDiff = S3Util.getBucketObjectKeyList(bookInfo.getBucketSourceName(), args[2], s3Client);//.getS3BucketFolderObjDiff(s3Client, args[0], bookName+"/data", args[1], bookName+"/data"); int diff = tiffDiff.size(); if (diff > 0) { System.out.println("There are totally " + String.valueOf(diff) + " tiff images to process.\nStart processing at " + (new java.util.Date()).toString()); AwsDataProcessorThreadFactory threadFactory = new AwsDataProcessorThreadFactory(); for (int i = 0; i <= 10; i++) { // S3TiffProcessorThread s3TiffProcessorThread = new S3TiffProcessorThread(s3Client, bookInfo, String.valueOf(i)+".tif", tiffDiff); // threadFactory.setIndex(i); // threadFactory.setJobType("small-tiff-" + bookName); // executor.execute(threadFactory.newThread(s3TiffProcessorThread)); // System.out.println("obj has path = "+bookInfo.getBucketSourceName() + tiffDiff.get(i)); S3TiffMetadataProcessorThread thread = new S3TiffMetadataProcessorThread(s3Client, bookInfo, String.valueOf(i) + ".tif", tiffDiff); threadFactory.setIndex(i); threadFactory.setJobType("tiff-metadata-" + bookName); executor.execute(threadFactory.newThread(thread)); } } else { System.out.println("There are no tiff images to process"); } executor.shutdown(); while (!executor.isTerminated()) { } System.out.println("All the derivatives were generated at " + (new java.util.Date()).toString() + "!"); } catch (Exception ex) { ex.printStackTrace();//logger.error("Cannot finish generating the small tiff images" + ex.getMessage()); } }
From source file:oulib.aws.s3.S3Util.java
/** * Use the default approach to get a AWS S3 client with the default region of east. * //w ww . ja v a 2 s. c o m * @return AmazonS3 : s3 client */ public static AmazonS3 getS3AwsClient() { AWSCredentials credentials = null; try { ProfileCredentialsProvider provider = new ProfileCredentialsProvider("default"); credentials = provider.getCredentials(); if (null == credentials) { throw new InvalidS3CredentialsException("Invalid credentials with default approach!"); } } catch (InvalidS3CredentialsException | AmazonClientException 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 (/Users/zhao0677/.aws/credentials), and is in valid format.", e); } AmazonS3 s3client = new AmazonS3Client(credentials); Region usEast = Region.getRegion(Regions.US_EAST_1); s3client.setRegion(usEast); return s3client; }
From source file:oulib.aws.s3.S3Util.java
public static AmazonS3 getS3Client() { AWSCredentials credentials = null;//from w w w . jav a 2 s . c om try { credentials = new ProfileCredentialsProvider("default").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 (/Users/zhao0677/.aws/credentials), and is in valid format.", e); } AmazonS3 s3client = new AmazonS3Client(credentials); Region usEast = Region.getRegion(Regions.US_EAST_1); s3client.setRegion(usEast); return s3client; }
From source file:pa3.RemoteClientSQS.java
License:Open Source License
/** * The only information needed to create a client are security credentials * consisting of the AWS Access Key ID and Secret Access Key. All other * configuration, such as the service endpoints, are performed * automatically. Client parameters, such as proxies, can be specified in an * optional ClientConfiguration object when constructing a client. * * @see com.amazonaws.auth.BasicAWSCredentials * @see com.amazonaws.auth.ProfilesConfigFile * @see com.amazonaws.ClientConfiguration *///from www.j a v a 2s . co m private static void initSQSandDynamoDB() throws Exception { /* * The ProfileCredentialsProvider will return your [default] credential * profile by reading from the credentials file located at * (C:\\Users\\HP\\.aws\\credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("default").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 (C:\\Users\\HP\\.aws\\credentials), and is in valid format.", e); } dynamoDB = new AmazonDynamoDBClient(credentials); sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDB.setRegion(usWest2); sqs.setRegion(usWest2); }
From source file:pa3.RemoteWorkerSQS.java
License:Open Source License
/** * The only information needed to create a client are security credentials * consisting of the AWS Access Key ID and Secret Access Key. All other * configuration, such as the service endpoints, are performed * automatically. Client parameters, such as proxies, can be specified in an * optional ClientConfiguration object when constructing a client. *//from w ww. j a v a 2s .c o m * @see com.amazonaws.auth.BasicAWSCredentials * @see com.amazonaws.auth.ProfilesConfigFile * @see com.amazonaws.ClientConfiguration */ private static void initSQSandDynamoDB() throws Exception { /* * The ProfileCredentialsProvider will return your [default] credential * profile by reading from the credentials file located at * (C:\\Users\\HP\\.aws\\credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("default").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 (C:\\Users\\HP\\.aws\\credentials), and is in valid format.", e); } dynamoDB = new AmazonDynamoDBClient(credentials); sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDB.setRegion(usWest2); sqs.setRegion(usWest2); }
From source file:pagerank.S3Wrapper.java
License:Open Source License
private void init() { /*// ww w .j a v a 2s.c o m * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (/home/yupenglu/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("default").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 (/home/yupenglu/.aws/credentials), and is in valid format.", e); } s3 = new AmazonS3Client(credentials); System.out.println("==========================================="); System.out.println("Getting Started with Amazon S3"); System.out.println("===========================================\n"); objectListing = s3.listObjects(new ListObjectsRequest().withBucketName(bucketName)); isTruncated = objectListing.isTruncated(); }