本文整理匯總了Java中com.amazonaws.auth.profile.ProfileCredentialsProvider類的典型用法代碼示例。如果您正苦於以下問題:Java ProfileCredentialsProvider類的具體用法?Java ProfileCredentialsProvider怎麽用?Java ProfileCredentialsProvider使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ProfileCredentialsProvider類屬於com.amazonaws.auth.profile包,在下文中一共展示了ProfileCredentialsProvider類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAWSCredentialsProviderChain
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
public static AWSCredentialsProviderChain getAWSCredentialsProviderChain() {
String cerberusRoleToAssume = System.getenv(CERBERUS_ASSUME_ROLE_ARN) != null ?
System.getenv(CERBERUS_ASSUME_ROLE_ARN) : "";
String cerberusRoleToAssumeExternalId = System.getenv(CERBERUS_ASSUME_ROLE_EXTERNAL_ID) != null ?
System.getenv(CERBERUS_ASSUME_ROLE_EXTERNAL_ID) : "";
STSAssumeRoleSessionCredentialsProvider sTSAssumeRoleSessionCredentialsProvider =
new STSAssumeRoleSessionCredentialsProvider
.Builder(cerberusRoleToAssume, UUID.randomUUID().toString())
.withExternalId(cerberusRoleToAssumeExternalId)
.build();
AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain(
new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
new ProfileCredentialsProvider(),
sTSAssumeRoleSessionCredentialsProvider,
new InstanceProfileCredentialsProvider());
return chain;
}
示例2: remove
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
public void remove(Object[] params) {
AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
try {
s3client.deleteObject(new DeleteObjectRequest(bucketName, params[0].toString()));
} catch (AmazonServiceException ase) {
System.out.println("Caught an AmazonServiceException, which " +
"means your request made it " +
"to Amazon S3, 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 " +
"an internal error while trying to " +
"communicate with S3, " +
"such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
}
}
示例3: setupS3
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
@BeforeClass
public static void setupS3() {
final ProfileCredentialsProvider credentialsProvider
= new ProfileCredentialsProvider(System.getenv("AWS_PROFILE"));
s3Client = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider).build();
bucket = System.getenv("AWS_S3_BUCKET");
if (! s3Client.doesBucketExist(bucket)) {
if (System.getenv("AWS_S3_CREATE_BUCKET") == null
|| !Boolean.parseBoolean(System.getenv("AWS_S3_CREATE_BUCKET"))) {
throw new IllegalStateException("Bucket does not exist and not allowed to create.");
}
s3Client.createBucket(bucket);
}
S3SecretHandler.setS3CredentialsProvider(credentialsProvider);
secretHandler = new S3SecretHandler();
}
示例4: BaseAmazonGlacierClientAware
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
protected BaseAmazonGlacierClientAware(String region, String account, String vault) {
this.region = region;
this.account = account;
this.vault = vault;
//@TODO Need to move away from deprecated fashion of acquiring a client
//@TODO Also, consider supporting other ways of passing credentials (other than relying of local .aws profile)
// load the credentials from the .aws profile
this.credentialsProvider = new ProfileCredentialsProvider();
this.awsClient = new AmazonGlacierClient(this.credentialsProvider);
// Set Glacier end-point
this.awsClient.setEndpoint("https://glacier." + this.region + ".amazonaws.com/");
}
示例5: AbstractS3Action
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
public AbstractS3Action( FileSystemIO delegate, Map<String, ?> env )
{
this.delegate = delegate;
AWSCredentials credentials;
try {
credentials = new ProfileCredentialsProvider().getCredentials();
}
catch( Exception ex ) {
throw new AmazonClientException( "Cannot load the credentials from the credential profiles file. "
+ "Please make sure that your credentials file is at the correct "
+ "location (~/.aws/credentials), and is in valid format.",
ex );
}
s3 = new AmazonS3Client( credentials );
Region region = Region.getRegion( Regions.EU_WEST_1 );
s3.setRegion( region );
String n = FileSystemUtils.get( env, BUCKET_READ );
if( n == null || n.trim().isEmpty() ) {
n = FileSystemUtils.get( env, BUCKET );
}
bucketName = Objects.requireNonNull( n, BUCKET + " or " + BUCKET_READ + " is not defined" );
}
示例6: Processor
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
public Processor(ProcessorConfig config) {
ProfileCredentialsProvider creds = new ProfileCredentialsProvider(config.profile());
creds.getCredentials(); // credible credential criteria
if (config.disableCerts())
System.setProperty("com.amazonaws.sdk.disableCertChecking", "true");
// Rekognition init
rek = new AmazonRekognitionClient(creds);
if (config.endpointOverride())
rek.setEndpoint(config.endpoint());
minConfidence = Integer.parseInt(config.confidence());
// The SQS queue to find jobs on
sqs = new AmazonSQSClient(creds);
queueUrl = sqs.createQueue(config.queue()).getQueueUrl();
// Processors
if (config.wantCloudSearch())
processors.add(new CloudSearchIndexer(creds, config.cloudSearch()));
if (config.wantDynamo())
processors.add(new DynamoWriter(creds, config.dynamo()));
if (config.wantTags3())
processors.add(new S3ObjectTagger(creds, config.tagPrefix()));
// Executor Service
int maxWorkers = Integer.parseInt(config.concurrency());
executor = new ThreadPoolExecutor(
1, maxWorkers, 30, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(maxWorkers * 2, false),
new CallerRunsPolicy() // prevents backing up too many jobs
);
maxImagesToProcess = Long.parseLong(config.max());
}
示例7: list
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
@Override
@SuppressWarnings("unused")
public List<AwsFileMiniModel> list(String prefix) {
AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
List<AwsFileMiniModel> files = new ArrayList();
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(prefix);
ObjectListing objectListing;
do {
objectListing = s3client.listObjects(listObjectsRequest);
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
System.out.println(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"
+ " (date = " + objectSummary.getLastModified() + ")");
files.add(new AwsFileMiniModel(objectSummary.getKey(), objectSummary.getLastModified()));
}
listObjectsRequest.setMarker(objectListing.getNextMarker());
} while (objectListing.isTruncated());
return files;
}
示例8: configureS3
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
public AmazonS3 configureS3(){
/*
* Create your credentials file at ~/.aws/credentials (C:\Users\USER_NAME\.aws\credentials for Windows users)
* and save the following lines after replacing the underlined values with your own.
*
* [default]
* aws_access_key_id = YOUR_ACCESS_KEY_ID
* aws_secret_access_key = YOUR_SECRET_ACCESS_KEY
*/
AWSCredentials credentials = null;
try {
credentials = new ProfileCredentialsProvider().getCredentials();
} 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 (~/.aws/credentials), and is in valid format.",
e);
}
AmazonS3 s3 = new AmazonS3Client(credentials);
Region usEast1 = Region.getRegion(Regions.US_EAST_1);
s3.setRegion(usEast1);
return s3;
}
示例9: testFindOrCreateWeatherPipeJobBucket
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
@Test
public void testFindOrCreateWeatherPipeJobBucket() {
String jobID = null;
String bucketName = "fdgfhfdx2";
AWSInterface awsInterface = new AWSInterface(jobID, null);
jobID = "job1";
awsInterface = new AWSInterface(jobID, bucketName);
String output;
output = awsInterface.FindOrCreateWeatherPipeJobDirectory();
String answer = "s3n://fdgfhfdx2/";
assertEquals(answer, output);
AWSCredentials credentials = new ProfileCredentialsProvider("default").getCredentials();
// TODO: add better credential searching later
Region region = Region.getRegion(Regions.US_EAST_1);
AmazonS3Client s3client = new AmazonS3Client(credentials);
s3client.setRegion(region);
s3client.deleteBucket(bucketName);
System.out.println("FindOrCreateWeatherPipeJobBucket() is ok");
}
示例10: getAwsCredentials
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
AWSCredentials getAwsCredentials() {
// The ProfileCredentialsProvider will return your [default]
// credential profile by reading from the credentials file located at
// (~/.aws/credentials).
AWSCredentials credentials;
try {
credentials = new ProfileCredentialsProvider().getCredentials();
} 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 (~/.aws/credentials), and is in valid format.",
e);
}
return credentials;
}
示例11: getClientForAccount
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
private AmazonEC2Client getClientForAccount(final String accountId, final Region region) {
final AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient(new ProfileCredentialsProvider());
final AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(
"arn:aws:iam::ACCOUNT_ID:role/fullstop-role")
.withDurationSeconds(3600).withRoleSessionName(
"fullstop-role");
final AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);
final BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(
assumeResult.getCredentials()
.getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(),
assumeResult.getCredentials().getSessionToken());
final AmazonEC2Client amazonEC2Client = new AmazonEC2Client(temporaryCredentials);
amazonEC2Client.setRegion(region);
return amazonEC2Client;
}
示例12: getCredentials
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
@Override
public AWSCredentials getCredentials() {
// if profile is specified, use that
final String profile = configuration.get(AWSConstants.PROFILE);
if(!StringUtils.isNullOrEmpty(profile)) {
return new ProfileCredentialsProvider(profile).getCredentials();
}
// then try access key and secret
final String accessKeyId = configuration.get(AWSConstants.ACCESS_KEY_ID);
final String secretAccessKey = configuration.get(AWSConstants.SECRET_ACCESS_KEY);
if(!StringUtils.isNullOrEmpty(accessKeyId) && !StringUtils.isNullOrEmpty(secretAccessKey)) {
return new BasicAWSCredentials(accessKeyId, secretAccessKey);
}
// fall back to default
return new DefaultAWSCredentialsProviderChain().getCredentials();
}
示例13: uploadS3
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
/**
* Upload file to S3.
*
* @param local
* - local file to upload.
* @return boolean
*/
boolean uploadS3(File local) {
boolean retval = false;
AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
try {
LOG.debug("Uploading a new object to S3 from local, file name "
+ local.getName());
s3client.putObject(new PutObjectRequest(bucketName, keyName, local));
retval = true;
} catch (AmazonServiceException ase) {
logAWSServiceException(ase);
} catch (AmazonClientException ace) {
logAWSClientException(ace);
}
return retval;
}
示例14: init
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
/**
* The only information needed to create a client are security credentials -
* your AWS Access Key ID and Secret Access Key. All other
* configuration, such as the service endpoints have defaults provided.
*
* Additional client parameters, such as proxy configuration, can be specified
* in an optional ClientConfiguration object when constructing a client.
*
* @see com.amazonaws.auth.BasicAWSCredentials
* @see com.amazonaws.auth.PropertiesCredentials
* @see com.amazonaws.ClientConfiguration
*/
private static void init() throws Exception {
/*
* ProfileCredentialsProvider loads AWS security credentials from a
* .aws/config file in your home directory.
*
* These same credentials are used when working with other AWS SDKs and the AWS CLI.
*
* You can find more information on the AWS profiles config file here:
* http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
*/
File configFile = new File(System.getProperty("user.home"), ".aws/credentials");
AWSCredentialsProvider credentialsProvider = new ProfileCredentialsProvider(
new ProfilesConfigFile(configFile), "default");
if (credentialsProvider.getCredentials() == null) {
throw new RuntimeException("No AWS security credentials found:\n"
+ "Make sure you've configured your credentials in: " + configFile.getAbsolutePath() + "\n"
+ "For more information on configuring your credentials, see "
+ "http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html");
}
ec2 = new AmazonEC2Client(credentialsProvider);
s3 = new AmazonS3Client(credentialsProvider);
}
示例15: open
import com.amazonaws.auth.profile.ProfileCredentialsProvider; //導入依賴的package包/類
@Override
public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
super.open(map, topologyContext, spoutOutputCollector);
try {
if (map.containsKey(Constants.S3_BUCKET_NAME)) {
bucketName = (String) map.get(Constants.S3_BUCKET_NAME);
}
if (map.containsKey(Constants.S3_KEY)) {
key = (String) map.get(Constants.S3_KEY);
}
credentials = new ProfileCredentialsProvider().getCredentials();
s3Client = new AmazonS3Client(credentials);
object = s3Client.getObject(
new GetObjectRequest(bucketName, key));
objectData = object.getObjectContent();
reader = new BufferedReader(new InputStreamReader(objectData));
} catch (Exception e) {
System.err.println("Error connecting to bucket." + e.getMessage());
}
}