/** * 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); }
public List<CredentialProfileEntry> getCredentialProfiles() { Map<String, BasicProfile> profiles = new ProfilesConfigFile().getAllBasicProfiles(); List<CredentialProfileEntry> credentialProfilesEntries = new ArrayList<>(); for (String profileName : profiles.keySet()) { credentialProfilesEntries.add(new CredentialProfileEntry(profileName, profiles.get(profileName))); } return credentialProfilesEntries; }
/** * Uses the given config file with the default profile name. */ public AWSProfileAuthModule(ProfilesConfigFile configFile) { this(configFile, ProfilesConfigFile.DEFAULT_PROFILE_NAME); }
/** * Uses the given config file and the specified named profile as your default. */ public AWSProfileAuthModule(ProfilesConfigFile configFile, String defaultProfileName) { super(new ProfileCredentialsProvider(configFile, defaultProfileName)); Objects.requireNonNull(configFile, "config file"); this.configFile = configFile; }