List of usage examples for com.amazonaws.auth.profile ProfileCredentialsProvider ProfileCredentialsProvider
public ProfileCredentialsProvider(ProfilesConfigFile profilesConfigFile, String profileName)
From source file:AwsSdkSample.java
License:Open Source License
/** * The only information needed to create a client are security credentials - * your AWS Access Key ID and Secret Access Key. All other * configuration, such as the service endpoints have defaults provided. * * Additional client parameters, such as proxy configuration, can be specified * in an optional ClientConfiguration object when constructing a client. * * @see com.amazonaws.auth.BasicAWSCredentials * @see com.amazonaws.auth.PropertiesCredentials * @see com.amazonaws.ClientConfiguration *///from w w w . j a v a 2s. com private static void init() throws Exception { /* * ProfileCredentialsProvider loads AWS security credentials from a * .aws/config file in your home directory. * * These same credentials are used when working with other AWS SDKs and the AWS CLI. * * You can find more information on the AWS profiles config file here: * http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html */ File configFile = new File(System.getProperty("user.home"), ".aws/credentials"); AWSCredentialsProvider credentialsProvider = new ProfileCredentialsProvider( new ProfilesConfigFile(configFile), "default"); if (credentialsProvider.getCredentials() == null) { throw new RuntimeException("No AWS security credentials found:\n" + "Make sure you've configured your credentials in: " + configFile.getAbsolutePath() + "\n" + "For more information on configuring your credentials, see " + "http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html"); } ec2 = new AmazonEC2Client(credentialsProvider); s3 = new AmazonS3Client(credentialsProvider); }
From source file:Aws.Profile.java
public ProfileCredentialsProvider LoadCredentials() { //Load credentials from file File configfile = new File(System.getProperty("user.home"), ".aws/credentials"); ProfilesConfigFile credentials = new ProfilesConfigFile(configfile); ArrayList CustomerList = getCustomerList(credentials); String profile = ProfileChoice(CustomerList); int client = CustomerList.indexOf(profile); ProfileCredentialsProvider provider = null; do {//from w w w . jav a 2s.c o m try { provider = new ProfileCredentialsProvider(credentials, CustomerList.get(client).toString()); } catch (ArrayIndexOutOfBoundsException ev) { System.out.println("No Profile present for the customer selected"); profile = ProfileChoice(CustomerList); client = CustomerList.indexOf(profile); provider = new ProfileCredentialsProvider(credentials, CustomerList.get(client).toString()); } } while (!profile.equals(CustomerList.get(client).toString())); return provider; }
From source file:com.dell.doradus.db.dynamodb.DynamoDBService.java
License:Apache License
private AWSCredentials getCredentials() { String awsProfile = getParamString("aws_profile"); if (!Utils.isEmpty(awsProfile)) { m_logger.info("Using AWS profile: {}", awsProfile); ProfileCredentialsProvider credsProvider = null; String awsCredentialsFile = getParamString("aws_credentials_file"); if (!Utils.isEmpty(awsCredentialsFile)) { credsProvider = new ProfileCredentialsProvider(awsCredentialsFile, awsProfile); } else {/* w w w .j a v a 2 s .c om*/ credsProvider = new ProfileCredentialsProvider(awsProfile); } return credsProvider.getCredentials(); } String awsAccessKey = getParamString("aws_access_key"); Utils.require(!Utils.isEmpty(awsAccessKey), "Either 'aws_profile' or 'aws_access_key' must be defined for tenant: " + m_tenant.getName()); String awsSecretKey = getParamString("aws_secret_key"); Utils.require(!Utils.isEmpty(awsSecretKey), "'aws_secret_key' must be defined when 'aws_access_key' is defined. " + "'aws_profile' is preferred over aws_access_key/aws_secret_key. Tenant: " + m_tenant.getName()); return new BasicAWSCredentials(awsAccessKey, awsSecretKey); }
From source file:org.pieShare.pieDrive.adapter.s3.S3Authentication.java
public boolean authenticate() { try {//from w ww. j a va 2 s . c o m provider = new ProfileCredentialsProvider(path, "default"); this.client = new AmazonS3Client(this.provider); client.createBucket(bucketName); } catch (AmazonServiceException e) { return false; } catch (AmazonClientException e) { return false; } return true; }
From source file:support.SQS.java
License:Open Source License
SQS() { try {/*from w ww . ja v a2s . c o m*/ credentials = new ProfileCredentialsProvider(key_path, "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\\Sayon\\.aws\\credentials), and is in valid format.", e); } ClientConfiguration clientConfiguration = new ClientConfiguration(); // clientConfiguration.setProxyHost(proxy_host); // clientConfiguration.setProxyPort(proxy_port); // clientConfiguration.setProxyUsername(proxy_username); // clientConfiguration.setProxyPassword(proxy_password); // sqs = new AmazonSQSClient(credentials, clientConfiguration); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sqs.setRegion(usWest2); }