Search in sources :

Example 76 with AWSCredentials

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);
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 77 with AWSCredentials

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;
    }
}
Also used : Region(com.amazonaws.regions.Region) ProfilesConfigFile(com.amazonaws.auth.profile.ProfilesConfigFile) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 78 with AWSCredentials

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();
}
Also used : PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) AmazonRoute53Client(com.amazonaws.services.route53.AmazonRoute53Client)

Example 79 with AWSCredentials

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);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AmazonSimpleDBClient(com.amazonaws.services.simpledb.AmazonSimpleDBClient) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) File(java.io.File)

Example 80 with AWSCredentials

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");
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) HashMap(java.util.HashMap) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) AWSCredentials(com.amazonaws.auth.AWSCredentials) Date(java.util.Date)

Aggregations

AWSCredentials (com.amazonaws.auth.AWSCredentials)277 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)181 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)80 Test (org.junit.Test)57 ClientConfiguration (com.amazonaws.ClientConfiguration)53 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)49 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)33 AmazonS3 (com.amazonaws.services.s3.AmazonS3)30 AmazonClientException (com.amazonaws.AmazonClientException)29 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)26 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)15 HashMap (java.util.HashMap)15 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)14 IOException (java.io.IOException)14 AmazonServiceException (com.amazonaws.AmazonServiceException)13 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)13 Date (java.util.Date)13 SdkClientException (com.amazonaws.SdkClientException)11 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)11 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)11