List of usage examples for com.amazonaws.auth DefaultAWSCredentialsProviderChain DefaultAWSCredentialsProviderChain
public DefaultAWSCredentialsProviderChain()
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;/* ww w. j a 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.kinesis.datavis.utils.DeleteSampleResources.java
License:Open Source License
public static void main(String[] args) { if (args.length != 4) { System.err.println("Usage: " + DeleteSampleResources.class.getSimpleName() + " <application name> <stream name> <DynamoDB table name> <region>"); System.exit(1);/*from w ww . j a v a2 s . c o m*/ } String applicationName = args[0]; String streamName = args[1]; String countsTableName = args[2]; Region region = AppUtils.parseRegion(args[3]); AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); ClientConfiguration clientConfig = AppUtils.configureUserAgentForSample(new ClientConfiguration()); AmazonKinesis kinesis = new AmazonKinesisClient(credentialsProvider, clientConfig); kinesis.setRegion(region); AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(credentialsProvider, clientConfig); dynamoDB.setRegion(region); StreamUtils streamUtils = new StreamUtils(kinesis); DynamoDBUtils dynamoDBUtils = new DynamoDBUtils(dynamoDB); LOG.info("Removing Amazon Kinesis and DynamoDB resources used by the sample application..."); streamUtils.deleteStream(streamName); // The Kinesis Client Library creates a table to manage shard leases and uses the application name for its name. dynamoDBUtils.deleteTable(applicationName); dynamoDBUtils.deleteTable(countsTableName); }
From source file:com.kinesis.datavis.writer.BidRequestStreamWriter.java
License:Open Source License
/** * Start a number of threads and send randomly generated {@link }s to a Kinesis Stream until the * program is terminated./*from w ww . j ava 2 s. com*/ * * @param args Expecting 3 arguments: A numeric value indicating the number of threads to use to send * data to Kinesis and the name of the stream to send records to, and the AWS region in which these resources * exist or should be created. * @throws InterruptedException If this application is interrupted while sending records to Kinesis. */ public static void main(String[] args) throws InterruptedException { int numberOfThreads = Integer.parseInt(args[0]); AppProperties appProps = new AppProperties("bidrq", args[1]); String streamName = appProps.streamName(); Region region = AppUtils.parseRegion(appProps.getRegion()); AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); ClientConfiguration clientConfig = AppUtils.configureUserAgentForSample(new ClientConfiguration()); AmazonKinesis kinesis = new AmazonKinesisClient(credentialsProvider, clientConfig); kinesis.setRegion(region); // The more resources we declare the higher write IOPS we need on our DynamoDB table. // We write a record for each resource every interval. // If interval = 500ms, resource count = 7 we need: (1000/500 * 7) = 14 write IOPS minimum. List<String> resources = new ArrayList<>(); resources.add("300x200"); resources.add("500x200"); resources.add("400x600"); resources.add("800x600"); List<String> bidRequestIds = new ArrayList<>(); // bidRequestIds.add(UUID.randomUUID().toString()); // bidRequestIds.add(UUID.randomUUID().toString()); // bidRequestIds.add(UUID.randomUUID().toString()); // bidRequestIds.add("11111111111"); // bidRequestIds.add("22222222222"); // bannerIds.add("33333333333"); // bidRequestIds.add("44444444444"); bidRequestIds.add("92b9b9d9-2d6d-454a-b80a-d6a318aca9ec"); BidRequestFactory bdFactory = new BidRequestFactory(bidRequestIds, resources); // Creates a stream to write to with 2 shards if it doesn't exist StreamUtils streamUtils = new StreamUtils(kinesis); streamUtils.createStreamIfNotExists(streamName, 2); LOG.info(String.format("%s stream is ready for use", streamName)); final BidRequestPutter putter = new BidRequestPutter(bdFactory, kinesis, streamName); GeneralStreamWriter streamWriter = new GeneralStreamWriter(numberOfThreads, putter); streamWriter.doWrite(); }
From source file:com.kitac.kinesissamples.consumer.communication.DynamoDBManager.java
License:Open Source License
private DynamoDBManager() { config = new ClientConfiguration(); /* TODO: ClientConfiguration setting code is here. */ AmazonDynamoDBClient client = new AmazonDynamoDBClient( // For use IAM role, specify DefaultAWSCredentialsProviderChain instance. new DefaultAWSCredentialsProviderChain(), config); client.setRegion(Regions.AP_NORTHEAST_1); dynamoDBConnection = new DynamoDB(client); }
From source file:com.kixeye.chassis.support.metrics.aws.DefaultCloudWatchFactory.java
License:Apache License
@Override public AmazonCloudWatchClient getCloudWatchClient() { AmazonCloudWatchClient client;/* www.j av a 2 s.c o m*/ if (StringUtils.isBlank(accessKeyId) || StringUtils.isBlank(secretKey)) { LOGGER.debug( "Constructing AmazonCloudWatchClient using DefaultAWSCredentialsProviderChain for region {}.", region); client = new AmazonCloudWatchClient(new DefaultAWSCredentialsProviderChain()); } else { LOGGER.debug("Constructing AmazonCloudWatchClient from given credentials for region {}.", region); client = new AmazonCloudWatchClient(new BasicAWSCredentials(accessKeyId, secretKey)); } client.setRegion(region); return client; }
From source file:com.liferay.portal.store.s3.S3Store.java
License:Open Source License
protected AWSCredentialsProvider getAWSCredentialsProvider() { if (Validator.isNotNull(_s3StoreConfiguration.accessKey()) && Validator.isNotNull(_s3StoreConfiguration.secretKey())) { AWSCredentials awsCredentials = new BasicAWSCredentials(_s3StoreConfiguration.accessKey(), _s3StoreConfiguration.secretKey()); return new StaticCredentialsProvider(awsCredentials); }//w ww. j ava 2 s .c o m return new DefaultAWSCredentialsProviderChain(); }
From source file:com.miovision.oss.awsbillingtools.examples.DefaultElasticsearchIndexerExampleApplication.java
License:Open Source License
private static S3BillingRecordLoader<DetailedLineItem> createRecordLoader(String bucketName, String awsAccountId) {// w ww. ja va2s . c o m AmazonS3 amazonS3 = new AmazonS3Client(new DefaultAWSCredentialsProviderChain()); S3BillingRecordFileScanner fileScanner = new S3BillingRecordFileScanner(amazonS3, bucketName, "", awsAccountId); DetailedLineItemParser parser = new DetailedLineItemParser(); return new S3BillingRecordLoader<>(amazonS3, fileScanner, parser); }
From source file:com.miovision.oss.awsbillingtools.examples.S3BillingRecordFileScannerExampleApplication.java
License:Open Source License
protected static S3BillingRecordFileScanner createBillingRecordFileScanner(String[] args) { if (args.length < 2) { System.err.println("Invalid arguments: expected <bucketName> and <awsAccountId>"); System.exit(-1);/*from ww w .j av a2 s .c o m*/ } // Construct an instance of AmazonS3 (the AWS S3 client) using the default credentials provider chain. This will // use all of the usual approaches to try and find AWS credentials. The easiest approach is to define the // environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. // // For more information: // http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html AmazonS3 amazonS3 = new AmazonS3Client(new DefaultAWSCredentialsProviderChain()); String bucketName = args[0]; // This is the AWS account ID of the billing files and NOT the AWS credentials. They may not be the same. String awsAccountId = args[1]; // The S3 prefix for where your billing files live. String prefix = ""; if (args.length > 2) { prefix = args[2]; } return new S3BillingRecordFileScanner(amazonS3, bucketName, prefix, awsAccountId); }
From source file:com.miovision.oss.awsbillingtools.examples.S3BillingRecordLoaderExampleApplication.java
License:Open Source License
protected static S3BillingRecordLoader<DetailedLineItem> createBillingRecordLoader(String[] args) { if (args.length < 2) { System.err.println("Invalid arguments: expected <bucketName> and <awsAccountId>"); System.exit(-1);/*from w ww .j a v a 2s . c om*/ } // Construct an instance of AmazonS3 (the AWS S3 client) using the default credentials provider chain. This will // use all of the usual approaches to try and find AWS credentials. The easiest approach is to define the // environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. // // For more information: // http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html AmazonS3 amazonS3 = new AmazonS3Client(new DefaultAWSCredentialsProviderChain()); String bucketName = args[0]; // This is the AWS account ID of the billing files and NOT the AWS credentials. They may not be the same. String awsAccountId = args[1]; // The S3 prefix for where your billing files live. String prefix = ""; if (args.length > 2) { prefix = args[2]; } S3BillingRecordFileScanner fileScanner = new S3BillingRecordFileScanner(amazonS3, bucketName, prefix, awsAccountId); DetailedLineItemParser billingRecordParser = new DetailedLineItemParser(); return new S3BillingRecordLoader<>(amazonS3, fileScanner, billingRecordParser); }
From source file:com.mweagle.tereus.aws.CloudFormation.java
License:Open Source License
public Optional<DescribeStacksResult> createStack(final CreateStackRequest request, final Region awsRegion, Logger logger) {/*from ww w. j av a 2s . c om*/ DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain(); final AmazonCloudFormationAsyncClient awsClient = new AmazonCloudFormationAsyncClient( credentialProviderChain.getCredentials()); awsClient.setRegion(awsRegion); logger.info("Creating stack: {}", request.getStackName()); Optional<DescribeStacksResult> completionResult = Optional.empty(); try { // There are no prior events for a creation request Future<CreateStackResult> createStackRequest = awsClient.createStackAsync(request); final CreateStackResult stackResult = createStackRequest.get(); logger.info("Stack ({}) creation in progress.", stackResult.getStackId()); completionResult = waitForStackComplete(awsClient, stackResult.getStackId(), Collections.emptyList(), logger); } catch (Exception ex) { logger.error(ex); } return completionResult; }