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:com.informatica.surf.sample.Util.java

License:Apache License

public static Worker createWorker(File conf, EventHandler<KinesisEvent> handler, String appName)
        throws IOException {
    Executor executor = Executors.newCachedThreadPool();
    Disruptor<KinesisEvent> disruptor = new Disruptor<>(KinesisEvent.EVENT_FACTORY, 128, executor);

    disruptor.handleEventsWith(handler);
    RingBuffer<KinesisEvent> buffer = disruptor.start();

    Properties props = new Properties();
    props.load(new FileReader(conf));
    // Generate a unique worker ID
    String workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID();
    String accessid = props.getProperty("aws-access-key-id");
    String secretkey = props.getProperty("aws-secret-key");
    String streamname = props.getProperty("aws-kinesis-stream-name");
    BasicAWSCredentials creds = new BasicAWSCredentials(accessid, secretkey);
    CredProvider credprovider = new CredProvider(creds);
    KinesisClientLibConfiguration config = new KinesisClientLibConfiguration(appName, streamname, credprovider,
            workerId);/*ww w.ja v  a  2 s . c  o m*/

    Worker worker = new Worker(new RecordProcessorFactory(buffer), config, new MetricsFactory());
    return worker;
}

From source file:com.informatica.surf.sources.kinesis.KinesisSource.java

License:Apache License

@Override
public void open(VDSConfiguration ctx) throws Exception {
    _logger.info("Initializing Kinesis Source");
    Executor executor = Executors.newCachedThreadPool();
    Disruptor<KinesisEvent> disruptor = new Disruptor<>(KinesisEvent.EVENT_FACTORY, 128, executor);
    disruptor.handleEventsWith(new EventHandler<KinesisEvent>() {
        @Override/*from w  w w  . j  av  a  2  s  .  co m*/
        public void onEvent(KinesisEvent kinesisEvent, long l, boolean b) throws Exception {
            _logger.debug("Received a Kinesis Event");
            _eventList.put(kinesisEvent);
            _logger.debug("eventlist size is now {}", _eventList.size());
        }
    });
    RingBuffer<KinesisEvent> buffer = disruptor.start();

    // Generate a unique worker ID
    String workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID();
    String accessid = ctx.getString("aws-access-key-id");
    String secretkey = ctx.getString("aws-secret-key");
    String streamname = ctx.getString("aws-kinesis-stream-name");
    String appName = ctx.optString("application-name", System.getProperty("nodename"));
    BasicAWSCredentials creds = new BasicAWSCredentials(accessid, secretkey);
    CredProvider credprovider = new CredProvider(creds);
    KinesisClientLibConfiguration config = new KinesisClientLibConfiguration(appName, streamname, credprovider,
            workerId).withMaxRecords(MAX_EVENTS);

    _worker = new Worker(new RecordProcessorFactory(buffer), config, new MetricsFactory());
    new Thread(_worker).start();
}

From source file:com.informatica.surf.target.kinesis.KinesisTarget.java

License:Apache License

@Override
public void open(VDSConfiguration ctx) throws Exception {
    String accessID = ctx.getString(ACCESS_KEY);
    String secretKey = ctx.getString(SECRET_KEY);
    _streamName = ctx.getString(STREAM_NAME);
    int tcount = ctx.optInt(THREAD_COUNT, 5);
    _threadpool = new ThreadPoolExecutor(tcount, tcount, 10, TimeUnit.SECONDS, new ArrayBlockingQueue(100),
            new ThreadPoolExecutor.CallerRunsPolicy()); // TODO: make the queue length configurable        
    BasicAWSCredentials creds = new BasicAWSCredentials(accessID, secretKey);
    _client = new AmazonKinesisAsyncClient(creds, _threadpool);
    _scheduler.scheduleAtFixedRate(_callback, 10, 10, TimeUnit.SECONDS); // TODO: make this configurable?

    _logger.info("Created connection to AWS Kinesis");
    _logger.info("Stream name: " + _streamName);
}

From source file:com.intuit.tank.persistence.databases.AmazonDynamoDatabaseDocApi.java

License:Open Source License

/**
 * /*from ww w. jav  a2 s  .  c o  m*/
 * @param dynamoDb
 */
public AmazonDynamoDatabaseDocApi() {
    CloudCredentials creds = new TankConfig().getVmManagerConfig().getCloudCredentials(CloudProvider.amazon);
    if (creds != null && StringUtils.isNotBlank(creds.getKeyId())) {
        AWSCredentials credentials = new BasicAWSCredentials(creds.getKeyId(), creds.getKey());
        this.dynamoDb = new AmazonDynamoDBClient(credentials, new ClientConfiguration());
    } else {
        this.dynamoDb = new AmazonDynamoDBClient(new ClientConfiguration());
    }

}

From source file:com.intuit.tank.vmManager.environment.amazon.AmazonS3.java

License:Open Source License

/**
 * //from w ww.j  av a 2 s.c om
 */
public AmazonS3() {

    try {
        CloudCredentials creds = new TankConfig().getVmManagerConfig()
                .getCloudCredentials(CloudProvider.amazon);
        ClientConfiguration config = new ClientConfiguration();
        if (StringUtils.isNotBlank(System.getProperty("http.proxyHost"))) {
            try {
                config.setProxyHost(System.getProperty("http.proxyHost"));
                if (StringUtils.isNotBlank(System.getProperty("http.proxyPort"))) {
                    config.setProxyPort(Integer.valueOf(System.getProperty("http.proxyPort")));
                }
            } catch (NumberFormatException e) {
                LOG.error("invalid proxy setup.");
            }

        }
        if (StringUtils.isNotBlank(creds.getKeyId()) && StringUtils.isNotBlank(creds.getKey())) {
            BasicAWSCredentials credentials = new BasicAWSCredentials(creds.getKeyId(), creds.getKey());
            this.s3Client = new AmazonS3Client(credentials, config);
        } else {
            this.s3Client = new AmazonS3Client(config);
        }
    } catch (Exception ex) {
        LOG.error(ex.getMessage());
        throw new RuntimeException(ex);
    }
}

From source file:com.intuit.tank.vmManager.environment.amazon.CloudwatchInstance.java

License:Open Source License

/**
 * /*from w  w  w  .  jav a2 s.c o m*/
 * @param request
 * @param vmRegion
 */
public CloudwatchInstance(VMRegion vmRegion) {
    // In case vmRegion is passed as null, use default region from settings file
    if (vmRegion == null) {
        vmRegion = config.getVmManagerConfig().getDefaultRegion();
    }
    try {
        CloudCredentials creds = config.getVmManagerConfig().getCloudCredentials(CloudProvider.amazon);
        AWSCredentials credentials = new BasicAWSCredentials(creds.getKeyId(), creds.getKey());
        ClientConfiguration clientConfig = new ClientConfiguration();
        clientConfig.setMaxConnections(2);
        if (StringUtils.isNotBlank(creds.getProxyHost())) {
            try {
                clientConfig.setProxyHost(creds.getProxyHost());

                if (StringUtils.isNotBlank(creds.getProxyPort())) {
                    clientConfig.setProxyPort(Integer.valueOf(creds.getProxyPort()));
                }
            } catch (NumberFormatException e) {
                logger.error("invalid proxy setup.");
            }

        }
        if (StringUtils.isNotBlank(creds.getKeyId()) && StringUtils.isNotBlank(creds.getKey())) {
            asynchCloudWatchClient = new AmazonCloudWatchAsyncClient(credentials, clientConfig,
                    Executors.newFixedThreadPool(2));
            asyncSnsClient = new AmazonSNSAsyncClient(credentials, clientConfig,
                    Executors.newFixedThreadPool(2));
        } else {
            asynchCloudWatchClient = new AmazonCloudWatchAsyncClient(clientConfig);
            asyncSnsClient = new AmazonSNSAsyncClient(clientConfig);
        }
        asynchCloudWatchClient.setRegion(Region.getRegion(Regions.fromName(vmRegion.getRegion())));
        asyncSnsClient.setRegion(Region.getRegion(Regions.fromName(vmRegion.getRegion())));
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        throw new RuntimeException(ex);
    }
}

From source file:com.irurueta.server.commons.email.AWSMailSender.java

License:Apache License

/**
 * Prepares client by setting proper credentials.
 *///ww  w.  j a va 2  s .  c o  m
private synchronized void prepareClient() {
    if (mClient == null) {
        //instantiate new client if needed
        if (areValidCredentials()) {
            mClient = new AmazonSimpleEmailServiceClient(
                    new BasicAWSCredentials(mCredentials.getAccessKey(), mCredentials.getSecretKey()));
        } else {
            //disabling mail sending
            mEnabled = false;
            Logger.getLogger(AWSMailSender.class.getName()).log(Level.INFO,
                    "AWS Email Sender disabled. " + "Invalid credentials");
        }
    }
}

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.util.AwsCredentialUtil.java

License:Open Source License

public static AWSCredentials getAWSCredentials(String awsAccessKey, String awsSecretKey, String roleARN) {
    AWSCredentials awsCredentials;//from w w  w . ja va2s .c  o m
    if (isNotEmpty(awsAccessKey) && isNotEmpty(awsSecretKey)) {
        awsCredentials = new BasicAWSCredentials(awsAccessKey.trim(), awsSecretKey.trim());

        // Use user long-term credentials to call the
        // AWS Security Token Service (STS) AssumeRole API, specifying
        // the ARN for the role -RO-role in amazon account.
        if (isNotEmpty(roleARN)) {
            AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient(awsCredentials);

            AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(roleARN.trim())
                    .withRoleSessionName("JRSRequest");

            AssumeRoleResult assumeResult = null;
            try {
                assumeResult = stsClient.assumeRole(assumeRequest);
            } catch (Exception ex) {
                logger.error(ex);
                throw new JSShowOnlyErrorMessage(ex.getMessage());
            }

            // AssumeRole returns temporary security credentials for
            // the IAM role.
            awsCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(),
                    assumeResult.getCredentials().getSecretAccessKey(),
                    assumeResult.getCredentials().getSessionToken());
        }
    } else {
        //Try getting Ec2 instance credentials.
        AWSCredentialsProvider instanceCredentialsProvider = new DefaultAWSCredentialsProviderChain();
        try {
            awsCredentials = instanceCredentialsProvider.getCredentials();
        } catch (Exception ex) {
            ApplicationContext ctx = StaticApplicationContext.getApplicationContext();
            MessageSource message = ctx.getBean("messageSource", MessageSource.class);

            logger.error("Exception loading default JRS instance credentials", ex);
            throw new JSShowOnlyErrorMessage(
                    message.getMessage("aws.exception.datasource.load.default.credentials", null,
                            LocaleContextHolder.getLocale()));
        }
    }
    return awsCredentials;
}

From source file:com.jktsoftware.amazondownloader.download.S3TypeBucket.java

License:Open Source License

public List<IObject> getObjectsInRepo() {
    String repoid = getRepoId();/*from   w ww  .  j a v  a2  s.com*/
    AWSCredentials awscredentials = new BasicAWSCredentials(this.credentials.getAccessKey(),
            this.credentials.getSecretAccessKey());

    AmazonS3 s3 = new AmazonS3Client(awscredentials);
    s3.setEndpoint(endpoint);

    System.out.println("Getting objects");
    ObjectListing objectListing = s3.listObjects(repoid);

    List<IObject> objects = new ArrayList<IObject>();

    for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
        S3TypeObject obj = new S3TypeObject(objectSummary.getKey(), objectSummary.getSize(),
                objectSummary.getBucketName(), objectSummary.getStorageClass(), s3);
        objects.add(obj);
    }
    return objects;
}

From source file:com.jktsoftware.amazondownloader.queuemanager.DownloaderQueueManager.java

License:Open Source License

public void CreateQueues() {
    AWSCredentials awscredentials = new BasicAWSCredentials(this._credentials.getAccessKey(),
            this._credentials.getSecretAccessKey());

    _sqs = new AmazonSQSClient(awscredentials);
    Region euWest1 = Region.getRegion(Regions.EU_WEST_1);
    _sqs.setRegion(euWest1);/*  www  .  j av  a2s .co  m*/

    System.out.println("Creating amazon download queues.\n");

    CreateQueueRequest createReceivedQueueRequest = new CreateQueueRequest(_receivedqueuename);

    this._receivedqueueurl = _sqs.createQueue(createReceivedQueueRequest).getQueueUrl();

    CreateQueueRequest createFailedQueueRequest = new CreateQueueRequest(_failedqueuename);

    this._failedqueueurl = _sqs.createQueue(createFailedQueueRequest).getQueueUrl();
}