Example usage for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials

List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials

Introduction

In this page you can find the example usage for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials.

Prototype

public BasicAWSCredentials(String accessKey, String secretKey) 

Source Link

Document

Constructs a new BasicAWSCredentials object, with the specified AWS access key and AWS secret key.

Usage

From source file:io.radiowitness.kinesis.consumer.KclConfigFactory.java

License:Open Source License

private AWSCredentialsProvider credentials() {
    return new StaticCredentialsProvider(
            new BasicAWSCredentials(config.getAccessKeyId(), config.getSecretKey()));
}

From source file:io.radiowitness.kinesis.producer.KinesisClientFactory.java

License:Open Source License

public KinesisClientFactory(KinesisConfig config, ExecutorService executor) {
    this.config = config;
    this.executor = executor;
    credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getSecretKey());
    clientConfig = clientConfig();/*from  ww w  .  ja  v a 2 s .c o  m*/
}

From source file:io.robrose.hop.watermap.aws.DynamoGeoClient.java

License:Open Source License

/**
 * The only information needed to create a client are security credentials
 * consisting of the AWS Access Key ID and Secret Access Key. All other
 * configuration, such as the service endpoints, are performed
 * automatically. Client parameters, such as proxies, can be specified in an
 * optional ClientConfiguration object when constructing a client.
 *
 * @see com.amazonaws.auth.BasicAWSCredentials
//   * @see com.amazonaws.auth.ProfilesConfigFile
 * @see com.amazonaws.ClientConfiguration
 *//*from   ww w  .  j  a  va 2  s .c o m*/

public static void init() {
    if (initialized)
        return;

    /*
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * (C:\\Users\\Robert\\.aws\\credentials).
     */

    AWSCredentials credentials;
    try {
        credentials = new BasicAWSCredentials(accessKey, secretKey);
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                + "Please make sure that your credentials file is at the correct "
                + "location (C:\\Users\\Robert\\.aws\\credentials), and is in valid format.", e);
    }
    dynamoDB = new AmazonDynamoDBClient(credentials);
    Region usEast1 = Region.getRegion(Regions.US_EAST_1);
    dynamoDB.setRegion(usEast1);

    initialized = true;
}

From source file:io.seldon.resources.external.S3FileStreamer.java

License:Apache License

@Autowired
public S3FileStreamer(@Value("${aws.key:}") String awsKey, @Value("${aws.secret:}") String awsSecret) {
    if (awsKey == null || awsKey.equals("") || awsSecret == null || awsSecret.equals("")) {
        creds = null;//from  w  ww.j  a  v  a 2 s.co m
    } else {
        this.creds = new BasicAWSCredentials(awsKey, awsSecret);
    }
}

From source file:io.stallion.services.S3StorageService.java

License:Open Source License

public S3StorageService() {
    CloudStorageSettings settings = Settings.instance().getCloudStorage();
    if (settings == null) {
        throw new ConfigException(
                "You are missing the section [cloudStorage]\naccessToken=...\nsecret=... in your stallion.toml");
    }// w w w .  j  a  v  a  2 s.  c o m
    if (empty(settings.getAccessToken())) {
        throw new ConfigException(
                "You are missing the setting accessKey in the stallion.toml section [cloudStorage]");
    }
    if (empty(settings.getSecret())) {
        throw new ConfigException(
                "You are missing the setting secret in the stallion.toml section [cloudStorage]");
    }
    accessToken = settings.getAccessToken();
    secret = settings.getSecret();
    AWSCredentials credentials = new BasicAWSCredentials(accessToken, secret);
    client = new AmazonS3Client(credentials);
}

From source file:io.starter.messaging.SNSMobilePush.java

License:Open Source License

private static AmazonSNS getSNS() throws IOException {
    String awsAccessKey = System.getProperty("AWS_ACCESS_KEY_ID"); // "YOUR_AWS_ACCESS_KEY";
    String awsSecretKey = System.getProperty("AWS_SECRET_KEY"); // "YOUR_AWS_SECRET_KEY";

    if (awsAccessKey == null)
        awsAccessKey = AWS_ACCESS_KEY;/*from  www .  ja va 2 s  .  c  o  m*/
    if (awsSecretKey == null)
        awsSecretKey = AWS_SECRET_KEY;

    AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
    AmazonSNS sns = new AmazonSNSClient(credentials);

    sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
    return sns;
}

From source file:io.starter.messaging.SNSMobilePush.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*//w  w  w.j  av  a2  s .c  om
     * TODO: Be sure to fill in your AWS access credentials in the
     * AwsCredentials.properties file before you try to run this sample.
     * http://aws.amazon.com/security-credentials
     */

    String awsAccessKey = System.getProperty("AWS_ACCESS_KEY_ID"); // "YOUR_AWS_ACCESS_KEY";
    String awsSecretKey = System.getProperty("AWS_SECRET_KEY"); // "YOUR_AWS_SECRET_KEY";

    if (awsAccessKey == null)
        awsAccessKey = AWS_ACCESS_KEY;
    if (awsSecretKey == null)
        awsSecretKey = AWS_SECRET_KEY;

    AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);

    AmazonSNS sns = new AmazonSNSClient(
            new PropertiesCredentials(SNSMobilePush.class.getResourceAsStream("AwsCredentials.properties")));

    // AmazonSNS sns = new AmazonSNSClient(credentials);

    sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
    System.out.println("===========================================\n");
    System.out.println("Initializing Communication with Amazon SNS");
    System.out.println("===========================================\n");
    try {
        SNSMobilePush sample = new SNSMobilePush(sns);
        /* TODO: Uncomment the services you wish to use. */
        // sample.starterAndroidAppNotification();
        // sample.starterKindleAppNotification();
        sample.starterAppleAppNotification();
        // sample.starterAppleSandboxAppNotification();
        // sample.starterBaiduAppNotification();
        // sample.starterWNSAppNotification();
        // sample.starterMPNSAppNotification();
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SNS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with SNS, such as not "
                + "being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:it.openutils.mgnlaws.magnolia.AmazonMgnlServletContextListener.java

License:Open Source License

protected void initEc2(String accessKey, String secretKey, String endpoint)
        throws IOException, AmazonEc2InstanceNotFound {
    String ec2InstanceId;/*from   w  w w  . j ava 2  s .c  o  m*/
    BufferedReader in = null;
    try {
        URL url = new URL("http://169.254.169.254/latest/meta-data/instance-id");
        URLConnection connection = url.openConnection();
        in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        ec2InstanceId = in.readLine();
        in.close();
    } finally {
        IOUtils.closeQuietly(in);
    }

    AmazonEC2Client client = new AmazonEC2Client(new BasicAWSCredentials(accessKey, secretKey));
    client.setEndpoint(endpoint);
    DescribeInstancesResult result = client
            .describeInstances(new DescribeInstancesRequest().withInstanceIds(ec2InstanceId));
    if (result.getReservations().size() > 0 && result.getReservations().get(0).getInstances().size() > 0) {
        ec2Instance = result.getReservations().get(0).getInstances().get(0);
        if (ec2Instance == null) {
            // should never happen
            throw new AmazonEc2InstanceNotFound(ec2InstanceId);
        }
    } else {
        throw new AmazonEc2InstanceNotFound(ec2InstanceId);
    }

    for (Tag tag : ec2Instance.getTags()) {
        if (StringUtils.startsWith(tag.getKey(), "__")) {
            System.setProperty(StringUtils.substring(tag.getKey(), 2), tag.getValue());
        } else {
            System.setProperty("aws.instance." + tag.getKey(), tag.getValue());
        }
    }

    String clusterId = System.getProperty(EC2_TAG_CLUSTERID);
    if (StringUtils.isNotEmpty(clusterId)) {
        System.setProperty(JR_CLUSTERID, clusterId);
    }
}

From source file:it.openutils.mgnlaws.magnolia.datastore.S3DataStore.java

License:Open Source License

/**
 * {@inheritDoc}/*from ww w  .ja va 2  s . com*/
 */
public void init(String homeDir) throws RepositoryException {
    // init S3 client
    amazonS3 = new AmazonS3Client(new BasicAWSCredentials(awsAccessKey, awsSecretKey));
    // set endpoint
    if (StringUtils.isNotBlank(endpoint)) {
        amazonS3.setEndpoint(endpoint);
    }
    // init transfer manager
    transferManager = new TransferManager(amazonS3);

    // initialize tmp directory
    if (StringUtils.isNotBlank(tmpPath)) {
        tmpDirectory = new File(tmpPath);
        if (!tmpDirectory.exists()) {
            tmpDirectory.mkdirs();
        }
    }
    if (tmpDirectory == null || !tmpDirectory.isDirectory()) {
        tmpDirectory = new File(System.getProperty("java.io.tmpdir"));
    }

    if (useCache) {
        // initialize cache directory
        if (StringUtils.isNotBlank(cacheDirectoryPath)) {
            cacheDirectory = new File(cacheDirectoryPath);
            if (!cacheDirectory.exists()) {
                cacheDirectory.mkdirs();
            }
        }
        if (cacheDirectory == null || !cacheDirectory.isDirectory()) {
            cacheDirectory = new File(System.getProperty("java.io.tmpdir"), cacheName);
            if (!cacheDirectory.exists()) {
                cacheDirectory.mkdirs();
            }
        }

        // create cache manager
        CacheManager cacheManager;
        if (StringUtils.startsWith(cacheConfigFile, "classpath:")) {
            URL configurationFileURL = getClass()
                    .getResource(StringUtils.substringAfter(cacheConfigFile, "classpath:"));
            cacheManager = CacheManager.newInstance(configurationFileURL);
        } else {
            cacheManager = CacheManager.newInstance(cacheConfigFile);
        }
        // get cache
        cache = cacheManager.getCache(cacheName);
        // register cache listener
        cache.getCacheEventNotificationService().registerListener(new S3CacheListener(cacheDirectory));
    }
}