Search in sources :

Example 1 with PropertiesCredentials

use of com.amazonaws.auth.PropertiesCredentials in project cas by apereo.

the class DynamoDbTicketRegistryConfiguration method amazonDynamoDbClient.

@RefreshScope
@Bean
public AmazonDynamoDBClient amazonDynamoDbClient() {
    try {
        final DynamoDbTicketRegistryProperties dynamoDbProperties = casProperties.getTicket().getRegistry().getDynamoDb();
        final ClientConfiguration cfg = new ClientConfiguration();
        cfg.setConnectionTimeout(dynamoDbProperties.getConnectionTimeout());
        cfg.setMaxConnections(dynamoDbProperties.getMaxConnections());
        cfg.setRequestTimeout(dynamoDbProperties.getRequestTimeout());
        cfg.setSocketTimeout(dynamoDbProperties.getSocketTimeout());
        cfg.setUseGzip(dynamoDbProperties.isUseGzip());
        cfg.setUseReaper(dynamoDbProperties.isUseReaper());
        cfg.setUseThrottleRetries(dynamoDbProperties.isUseThrottleRetries());
        cfg.setUseTcpKeepAlive(dynamoDbProperties.isUseTcpKeepAlive());
        cfg.setProtocol(Protocol.valueOf(dynamoDbProperties.getProtocol().toUpperCase()));
        cfg.setClientExecutionTimeout(dynamoDbProperties.getClientExecutionTimeout());
        cfg.setCacheResponseMetadata(dynamoDbProperties.isCacheResponseMetadata());
        if (StringUtils.isNotBlank(dynamoDbProperties.getLocalAddress())) {
            cfg.setLocalAddress(InetAddress.getByName(dynamoDbProperties.getLocalAddress()));
        }
        AWSCredentials credentials = null;
        if (dynamoDbProperties.getCredentialsPropertiesFile() != null) {
            credentials = new PropertiesCredentials(dynamoDbProperties.getCredentialsPropertiesFile().getInputStream());
        } else if (StringUtils.isNotBlank(dynamoDbProperties.getCredentialAccessKey()) && StringUtils.isNotBlank(dynamoDbProperties.getCredentialSecretKey())) {
            credentials = new BasicAWSCredentials(dynamoDbProperties.getCredentialAccessKey(), dynamoDbProperties.getCredentialSecretKey());
        }
        final AmazonDynamoDBClient client;
        if (credentials == null) {
            client = new AmazonDynamoDBClient(cfg);
        } else {
            client = new AmazonDynamoDBClient(credentials, cfg);
        }
        if (StringUtils.isNotBlank(dynamoDbProperties.getEndpoint())) {
            client.setEndpoint(dynamoDbProperties.getEndpoint());
        }
        if (StringUtils.isNotBlank(dynamoDbProperties.getRegion())) {
            client.setRegion(Region.getRegion(Regions.valueOf(dynamoDbProperties.getRegion())));
        }
        if (StringUtils.isNotBlank(dynamoDbProperties.getRegionOverride())) {
            client.setSignerRegionOverride(dynamoDbProperties.getRegionOverride());
        }
        if (StringUtils.isNotBlank(dynamoDbProperties.getServiceNameIntern())) {
            client.setServiceNameIntern(dynamoDbProperties.getServiceNameIntern());
        }
        if (dynamoDbProperties.getTimeOffset() != 0) {
            client.setTimeOffset(dynamoDbProperties.getTimeOffset());
        }
        return client;
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : DynamoDbTicketRegistryProperties(org.apereo.cas.configuration.model.support.dynamodb.DynamoDbTicketRegistryProperties) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Example 2 with PropertiesCredentials

use of com.amazonaws.auth.PropertiesCredentials in project YCSB by brianfrankcooper.

the class DynamoDBClient method init.

@Override
public void init() throws DBException {
    String debug = getProperties().getProperty("dynamodb.debug", null);
    if (null != debug && "true".equalsIgnoreCase(debug)) {
        LOGGER.setLevel(Level.DEBUG);
    }
    String configuredEndpoint = getProperties().getProperty("dynamodb.endpoint", null);
    String credentialsFile = getProperties().getProperty("dynamodb.awsCredentialsFile", null);
    String primaryKey = getProperties().getProperty("dynamodb.primaryKey", null);
    String primaryKeyTypeString = getProperties().getProperty("dynamodb.primaryKeyType", null);
    String consistentReads = getProperties().getProperty("dynamodb.consistentReads", null);
    String connectMax = getProperties().getProperty("dynamodb.connectMax", null);
    if (null != connectMax) {
        this.maxConnects = Integer.parseInt(connectMax);
    }
    if (null != consistentReads && "true".equalsIgnoreCase(consistentReads)) {
        this.consistentRead = true;
    }
    if (null != configuredEndpoint) {
        this.endpoint = configuredEndpoint;
    }
    if (null == primaryKey || primaryKey.length() < 1) {
        throw new DBException("Missing primary key attribute name, cannot continue");
    }
    if (null != primaryKeyTypeString) {
        try {
            this.primaryKeyType = PrimaryKeyType.valueOf(primaryKeyTypeString.trim().toUpperCase());
        } catch (IllegalArgumentException e) {
            throw new DBException("Invalid primary key mode specified: " + primaryKeyTypeString + ". Expecting HASH or HASH_AND_RANGE.");
        }
    }
    if (this.primaryKeyType == PrimaryKeyType.HASH_AND_RANGE) {
        // When the primary key type is HASH_AND_RANGE, keys used by YCSB
        // are range keys so we can benchmark performance of individual hash
        // partitions. In this case, the user must specify the hash key's name
        // and optionally can designate a value for the hash key.
        String configuredHashKeyName = getProperties().getProperty("dynamodb.hashKeyName", null);
        if (null == configuredHashKeyName || configuredHashKeyName.isEmpty()) {
            throw new DBException("Must specify a non-empty hash key name when the primary key type is HASH_AND_RANGE.");
        }
        this.hashKeyName = configuredHashKeyName;
        this.hashKeyValue = getProperties().getProperty("dynamodb.hashKeyValue", DEFAULT_HASH_KEY_VALUE);
    }
    try {
        AWSCredentials credentials = new PropertiesCredentials(new File(credentialsFile));
        ClientConfiguration cconfig = new ClientConfiguration();
        cconfig.setMaxConnections(maxConnects);
        dynamoDB = new AmazonDynamoDBClient(credentials, cconfig);
        dynamoDB.setEndpoint(this.endpoint);
        primaryKeyName = primaryKey;
        LOGGER.info("dynamodb connection created with " + this.endpoint);
    } catch (Exception e1) {
        LOGGER.error("DynamoDBClient.init(): Could not initialize DynamoDB client.", e1);
    }
}
Also used : PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) AWSCredentials(com.amazonaws.auth.AWSCredentials) File(java.io.File) ClientConfiguration(com.amazonaws.ClientConfiguration) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException)

Example 3 with PropertiesCredentials

use of com.amazonaws.auth.PropertiesCredentials 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 4 with PropertiesCredentials

use of com.amazonaws.auth.PropertiesCredentials 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 5 with PropertiesCredentials

use of com.amazonaws.auth.PropertiesCredentials 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

PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)14 AWSCredentials (com.amazonaws.auth.AWSCredentials)12 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)6 File (java.io.File)6 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)5 IOException (java.io.IOException)5 ClientConfiguration (com.amazonaws.ClientConfiguration)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)3 Instance (com.amazonaws.services.ec2.model.Instance)3 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)2 AmazonSimpleDBClient (com.amazonaws.services.simpledb.AmazonSimpleDBClient)2 RegionRecord (edu.umass.cs.aws.support.RegionRecord)2 Point2D (java.awt.geom.Point2D)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)2 Bean (org.springframework.context.annotation.Bean)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1