use of com.amazonaws.auth.AWSCredentials in project hadoop by apache.
the class AWSCredentialProviderList method getCredentials.
/**
* Iterate through the list of providers, to find one with credentials.
* If {@link #reuseLastProvider} is true, then it is re-used.
* @return a set of credentials (possibly anonymous), for authenticating.
*/
@Override
public AWSCredentials getCredentials() {
checkNotEmpty();
if (reuseLastProvider && lastProvider != null) {
return lastProvider.getCredentials();
}
AmazonClientException lastException = null;
for (AWSCredentialsProvider provider : providers) {
try {
AWSCredentials credentials = provider.getCredentials();
if ((credentials.getAWSAccessKeyId() != null && credentials.getAWSSecretKey() != null) || (credentials instanceof AnonymousAWSCredentials)) {
lastProvider = provider;
LOG.debug("Using credentials from {}", provider);
return credentials;
}
} catch (AmazonClientException e) {
lastException = e;
LOG.debug("No credentials provided by {}: {}", provider, e.toString(), e);
}
}
// no providers had any credentials. Rethrow the last exception
// or create a new one.
String message = "No AWS Credentials provided by " + listProviderNames();
if (lastException != null) {
message += ": " + lastException;
}
throw new AmazonClientException(message, lastException);
}
use of com.amazonaws.auth.AWSCredentials in project openhab1-addons by openhab.
the class DynamoDBConfig method fromConfig.
/**
*
* @param config persistence service configuration
* @return DynamoDB configuration. Returns null in case of configuration errors
*/
public static DynamoDBConfig fromConfig(Map<String, Object> config) {
if (config == null || config.isEmpty()) {
logger.error("Configuration not provided! At least AWS region and credentials must be provided.");
return null;
}
try {
String regionName = (String) config.get("region");
if (isBlank(regionName)) {
invalidRegionLogHelp(regionName);
return null;
}
final Region region;
try {
region = Region.getRegion(Regions.fromName(regionName));
} catch (IllegalArgumentException e) {
invalidRegionLogHelp(regionName);
return null;
}
AWSCredentials credentials;
String accessKey = (String) config.get("accessKey");
String secretKey = (String) config.get("secretKey");
if (!isBlank(accessKey) && !isBlank(secretKey)) {
logger.debug("accessKey and secretKey specified. Using those.");
credentials = new BasicAWSCredentials(accessKey, secretKey);
} else {
logger.debug("accessKey and/or secretKey blank. Checking profilesConfigFile and profile.");
String profilesConfigFile = (String) config.get("profilesConfigFile");
String profile = (String) config.get("profile");
if (isBlank(profilesConfigFile) || isBlank(profile)) {
logger.error("Specify either 1) accessKey and secretKey; or 2) profilesConfigFile and " + "profile for providing AWS credentials");
return null;
}
credentials = new ProfilesConfigFile(profilesConfigFile).getCredentials(profile);
}
String table = (String) config.get("tablePrefix");
if (isBlank(table)) {
logger.debug("Using default table name {}", DEFAULT_TABLE_PREFIX);
table = DEFAULT_TABLE_PREFIX;
}
final boolean createTable;
String createTableParam = (String) config.get("createTable");
if (isBlank(createTableParam)) {
logger.debug("Creating table on demand: {}", DEFAULT_CREATE_TABLE_ON_DEMAND);
createTable = DEFAULT_CREATE_TABLE_ON_DEMAND;
} else {
createTable = Boolean.parseBoolean(createTableParam);
}
final long readCapacityUnits;
String readCapacityUnitsParam = (String) config.get("readCapacityUnits");
if (isBlank(readCapacityUnitsParam)) {
logger.debug("Read capacity units: {}", DEFAULT_READ_CAPACITY_UNITS);
readCapacityUnits = DEFAULT_READ_CAPACITY_UNITS;
} else {
readCapacityUnits = Long.parseLong(readCapacityUnitsParam);
}
final long writeCapacityUnits;
String writeCapacityUnitsParam = (String) config.get("writeCapacityUnits");
if (isBlank(writeCapacityUnitsParam)) {
logger.debug("Write capacity units: {}", DEFAULT_WRITE_CAPACITY_UNITS);
writeCapacityUnits = DEFAULT_WRITE_CAPACITY_UNITS;
} else {
writeCapacityUnits = Long.parseLong(writeCapacityUnitsParam);
}
return new DynamoDBConfig(region, credentials, table, createTable, readCapacityUnits, writeCapacityUnits);
} catch (Exception e) {
logger.error("Error with configuration", e);
return null;
}
}
use of com.amazonaws.auth.AWSCredentials in project GNS by MobilityFirst.
the class Route53 method main.
/**
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
AWSCredentials credentials = new PropertiesCredentials(AWSEC2.class.getResourceAsStream("resources/AwsCredentials.properties"));
//Create Amazon Client object
route53 = new AmazonRoute53Client(credentials);
listRecordSetsForHostedZone();
}
use of com.amazonaws.auth.AWSCredentials in project GNS by MobilityFirst.
the class AWSStatusCheck method init.
private static void init() throws Exception {
AWSCredentials credentials = new PropertiesCredentials(new File(CREDENTIALSFILE));
ec2 = new AmazonEC2Client(credentials);
s3 = new AmazonS3Client(credentials);
sdb = new AmazonSimpleDBClient(credentials);
}
use of com.amazonaws.auth.AWSCredentials in project GNS by MobilityFirst.
the class AWSEC2 method main.
/**
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
AWSCredentials credentials = new PropertiesCredentials(AWSEC2.class.getResourceAsStream(System.getProperty("user.home") + FILESEPARATOR + ".aws" + FILESEPARATOR + "credentials"));
//Create Amazon Client object
AmazonEC2 ec2 = new AmazonEC2Client(credentials);
RegionRecord region = RegionRecord.US_EAST_1;
String keyName = "aws";
String installScript = "#!/bin/bash\n" + "cd /home/ec2-user\n" + "yum --quiet --assumeyes update\n";
HashMap<String, String> tags = new HashMap<>();
tags.put("runset", new Date().toString());
createAndInitInstance(ec2, region, AMIRecord.getAMI(AMIRecordType.Amazon_Linux_AMI_2013_03_1, region), "Test Instance", keyName, DEFAULT_SECURITY_GROUP_NAME, installScript, tags, "23.21.120.250");
}
Aggregations