List of usage examples for com.amazonaws.auth InstanceProfileCredentialsProvider InstanceProfileCredentialsProvider
@Deprecated
public InstanceProfileCredentialsProvider()
From source file:org.rdswitchboard.utils.s3.find.App.java
License:Open Source License
public static void main(String[] args) { try {/* ww w .jav a 2 s.c o m*/ if (args.length != 2) throw new IllegalArgumentException("Bucket name and search string can not be empty"); String buckey = args[0]; String search = args[1]; String prefix = null; int pos = buckey.indexOf('/'); if (pos > 0) { prefix = buckey.substring(pos + 1); buckey = buckey.substring(0, pos); } AmazonS3 s3client = new AmazonS3Client(new InstanceProfileCredentialsProvider()); // AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider()); ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(buckey); if (!StringUtils.isNullOrEmpty(prefix)) listObjectsRequest.setPrefix(prefix); ObjectListing objectListing; do { objectListing = s3client.listObjects(listObjectsRequest); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { String key = objectSummary.getKey(); System.out.println(" - " + key); S3Object object = s3client.getObject(new GetObjectRequest(buckey, key)); String str = IOUtils.toString(object.getObjectContent()); if (str.contains(search)) { System.out.println("Found!"); FileUtils.writeStringToFile(new File("s3/" + key), str); } } listObjectsRequest.setMarker(objectListing.getNextMarker()); } while (objectListing.isTruncated()); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.researchgraph.crossref.CrossRef.java
public CrossRef(String cache) { URI uri = URI.create(cache); if (null == uri.getScheme()) { // local cache this.cache = new File(cache); this.cache.mkdirs(); File cacheWorks = new File(this.cache, CACHE_WORKS); cacheWorks.mkdirs();// ww w . ja v a 2 s .c om File cacheAuthority = new File(this.cache, CACHE_AUTHORITY); cacheAuthority.mkdirs(); this.s3Client = null; this.s3Bucket = null; this.s3Prefix = null; } else if (uri.getScheme().toLowerCase().equals(PROTOCOL_S3)) { this.s3Client = new AmazonS3Client(new InstanceProfileCredentialsProvider()); this.s3Bucket = uri.getHost(); this.s3Prefix = StringUtils.isEmpty(uri.getPath()) ? PREFIX_ROOT : uri.getPath(); this.cache = null; } else { throw new IllegalArgumentException("Invalid cache sheme: " + uri.getScheme()); } }
From source file:org.selman.tweetamo.TweetamoServer.java
License:Apache License
private static void configure(String propertiesFile) throws IOException { if (propertiesFile != null) { loadProperties(propertiesFile);/*from w ww . j a v a 2s . co m*/ } // ensure the JVM will refresh the cached IP values of AWS resources (e.g. service endpoints). java.security.Security.setProperty("networkaddress.cache.ttl", "60"); String workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID(); LOG.info("Using workerId: " + workerId); // Get credentials from IMDS. If unsuccessful, get them from the classpath. AWSCredentialsProvider credentialsProvider = null; try { credentialsProvider = new InstanceProfileCredentialsProvider(); // Verify we can fetch credentials from the provider credentialsProvider.getCredentials(); LOG.info("Obtained credentials from the IMDS."); } catch (AmazonClientException e) { LOG.info("Unable to obtain credentials from the IMDS, trying classpath properties", e); credentialsProvider = new ClasspathPropertiesFileCredentialsProvider(); // Verify we can fetch credentials from the provider credentialsProvider.getCredentials(); LOG.info("Obtained credentials from the properties file."); } LOG.info("Using credentials with access key id: " + credentialsProvider.getCredentials().getAWSAccessKeyId()); kinesisClientLibConfiguration = new KinesisClientLibConfiguration(applicationName, streamName, credentialsProvider, workerId); }
From source file:org.xmlsh.aws.gradle.AwsPluginExtension.java
License:BSD License
public AWSCredentialsProvider newCredentialsProvider(String profileName) { return new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), Strings.isNullOrEmpty(profileName) == false ? new ProfileCredentialsProvider(profileName) : EMPTY, new ProfileCredentialsProvider(this.profileName), new InstanceProfileCredentialsProvider()); }
From source file:uk.co.keithj.postcodelookup.infrastructure.repository.SpringDataDynamoDBConfigurator.java
License:Apache License
/** * The AWS Credentials are retrieved from $USER_HOME/.aws/credentials or * from Instance Profile when on AWS./*from w ww . j a va2s . co m*/ * * @return the AWS Credentials */ @Bean public AWSCredentials amazonAWSCredentials() { if (useProfileCredentials) { return new ProfileCredentialsProvider().getCredentials(); } else { return new InstanceProfileCredentialsProvider().getCredentials(); } }