com.amazonaws.auth.profile.ProfilesConfigFile Java Examples
The following examples show how to use
com.amazonaws.auth.profile.ProfilesConfigFile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsSdkSample.java From aws-sdk-java-archetype with Apache License 2.0 | 6 votes |
/** * 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 */ 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); }