本文整理匯總了Java中com.amazonaws.auth.InstanceProfileCredentialsProvider類的典型用法代碼示例。如果您正苦於以下問題:Java InstanceProfileCredentialsProvider類的具體用法?Java InstanceProfileCredentialsProvider怎麽用?Java InstanceProfileCredentialsProvider使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
InstanceProfileCredentialsProvider類屬於com.amazonaws.auth包,在下文中一共展示了InstanceProfileCredentialsProvider類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCredentialProviderC
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
public static AWSCredentialsProvider getCredentialProviderC(Parameters config){
List<AWSCredentialsProvider> providers = new ArrayList<AWSCredentialsProvider>();
if ("YES".equals(config.get("aws.credentials.instaneProfile")))
providers.add(new InstanceProfileCredentialsProvider());
if ("YES".equals(config.get("aws.credentials.environmentVariable")))
providers.add(new EnvironmentVariableCredentialsProvider());
if ("YES".equals(config.get("aws.credentials.systemProperties")))
providers.add(new SystemPropertiesCredentialsProvider());
String accessKey = config.get("aws.credentials.accessKey").toString();
String secretKey = config.get("aws.credentials.secretKey").toString();
if (accessKey != null && accessKey.length() > 0){
providers.add(new AWSCredentialsConfigFileProvider(accessKey, secretKey));
}
return new AWSCredentialsProviderChain(providers.toArray(new AWSCredentialsProvider[0]));
}
示例2: getAWSCredentialsProviderChain
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的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;
}
示例3: getAuthToken
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
String getAuthToken(String hostname, int port, String rdsUser, String rdsIamRole) {
InstanceProfileCredentialsProvider awsCredProvider = new InstanceProfileCredentialsProvider(true);
if (LOG.isDebugEnabled()) {
LOG.debug("getAuthToken: Access key id: {}", awsCredProvider.getCredentials().getAWSAccessKeyId());
}
RdsIamAuthTokenGenerator generator = RdsIamAuthTokenGenerator.builder()
.credentials(awsCredProvider)
.region(EC2MetadataUtils.getEC2InstanceRegion())
.build();
if (LOG.isDebugEnabled()) {
LOG.debug("Instance {} Port {} User {} Region: {} Role: {}", hostname, port, rdsUser,
EC2MetadataUtils.getEC2InstanceRegion(), rdsIamRole);
}
return generator.getAuthToken(GetIamAuthTokenRequest.builder()
.hostname(hostname).port(port).userName(rdsUser)
.build());
}
示例4: provideAmazonS3Client
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
@Singleton
@Provides
@Nullable
public AmazonS3 provideAmazonS3Client(@Nullable AWSCredentials awsCredentials, @Nullable EncryptionMaterialsProvider encryptionMaterialsProvider)
{
if (awsCredentials == null) {
if (encryptionMaterialsProvider == null) {
return new AmazonS3Client(new InstanceProfileCredentialsProvider());
}
else {
return new AmazonS3EncryptionClient(new InstanceProfileCredentialsProvider(), encryptionMaterialsProvider);
}
}
if (encryptionMaterialsProvider == null) {
return new AmazonS3Client(awsCredentials);
}
else {
return new AmazonS3EncryptionClient(awsCredentials, encryptionMaterialsProvider);
}
}
示例5: init
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
@PostConstruct
protected void init() {
configureAWSLogAgent();
credentialsProvider = new InstanceProfileCredentialsProvider();
region = Regions.getCurrentRegion();
amazonDynamoDB.setRegion(region);
dbPrefix = AmazonConfigProvider.getDynamoDbPrefix();
DynamoDBMapperConfig config = new DynamoDBMapperConfig.Builder().withTableNameOverride(DynamoDBMapperConfig.TableNameOverride.
withTableNamePrefix(dbPrefix)).build();
mapper = new DynamoDBMapper(amazonDynamoDB, config);
tablesWithPrefix = Arrays.stream(tables).map(s -> dbPrefix.concat(s)).collect(Collectors.toList());
if (customBucketName != null) {
customBucketName = customBucketName.toLowerCase();
}
if ((customBucketName.isEmpty() || CUSTOM_BUCKET_NAME_DEFAULT_VALUE.equals(customBucketName)) && !validateBucketName(customBucketName).isValid()) {
customBucketName = null;
}
}
示例6: getCredentials
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
public AWSCredentials getCredentials() {
AWSCredentials initialCredentials = new BasicAWSCredentials(accessKey, secretKey.getPlainText());
if (StringUtils.isBlank(iamRoleArn)) {
return initialCredentials;
} else {
// Handle the case of delegation to instance profile
if (StringUtils.isBlank(accessKey) && StringUtils.isBlank(secretKey.getPlainText()) ) {
initialCredentials = (new InstanceProfileCredentialsProvider()).getCredentials();
}
AssumeRoleRequest assumeRequest = createAssumeRoleRequest(iamRoleArn);
AssumeRoleResult assumeResult = new AWSSecurityTokenServiceClient(initialCredentials).assumeRole(assumeRequest);
return new BasicSessionCredentials(
assumeResult.getCredentials().getAccessKeyId(),
assumeResult.getCredentials().getSecretAccessKey(),
assumeResult.getCredentials().getSessionToken());
}
}
示例7: checkAwsEnvironmentVariables
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
public void checkAwsEnvironmentVariables(CloudCredential credential) {
AwsCredentialView awsCredential = new AwsCredentialView(credential);
if (isRoleAssumeRequired(awsCredential)) {
if (awsEnvironmentVariableChecker.isAwsAccessKeyAvailable() && !awsEnvironmentVariableChecker.isAwsSecretAccessKeyAvailable()) {
throw new CloudConnectorException("If 'AWS_ACCESS_KEY_ID' available then 'AWS_SECRET_ACCESS_KEY' must be set!");
} else if (awsEnvironmentVariableChecker.isAwsSecretAccessKeyAvailable() && !awsEnvironmentVariableChecker.isAwsAccessKeyAvailable()) {
throw new CloudConnectorException("If 'AWS_SECRET_ACCESS_KEY' available then 'AWS_ACCESS_KEY_ID' must be set!");
} else if (!awsEnvironmentVariableChecker.isAwsAccessKeyAvailable() && !awsEnvironmentVariableChecker.isAwsSecretAccessKeyAvailable()) {
try {
new InstanceProfileCredentialsProvider().getCredentials();
} catch (AmazonClientException ignored) {
StringBuilder sb = new StringBuilder();
sb.append("The 'AWS_ACCESS_KEY_ID' and 'AWS_SECRET_ACCESS_KEY' environment variables must be set ");
sb.append("or an instance profile role should be available.");
LOGGER.info(sb.toString());
throw new CloudConnectorException(sb.toString());
}
}
}
}
示例8: connectUserBucket
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
/**
* Connect to the specified bucket using previously given accesskey and secretkey.
* @param bucketName Name of the bucket to connect to
* @param pathPrefix Prefix that will be later used for filtering documents
* @throws AmazonS3Exception when access or secret keys are wrong or bucket does not exists
*/
public void connectUserBucket(String bucketName, String pathPrefix) throws AmazonS3Exception{
this.bucketName = bucketName;
this.pathPrefix = pathPrefix;
if (accessKey != null && secretKey != null) {
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
s3Client = new AmazonS3Client(credentials);
} else if (useIAMRoleForEC2) {
// Force usage of IAM Role process as described into
// http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-roles.html.
s3Client = new AmazonS3Client(new InstanceProfileCredentialsProvider());
} else {
// Default credentials retrieval or IAM Role process as described into
// http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-roles.html.
s3Client = new AmazonS3Client();
}
// Getting location seems odd as we don't use it later and doesBucketExists() seems
// more appropriate... However, this later returns true even for non existing buckets !
s3Client.getBucketLocation(bucketName);
}
示例9: createAmazonS3Client
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
public static AmazonS3Client createAmazonS3Client(Configuration conf)
/* */ {
/* 452 */ String accessKeyId = conf.get("fs.s3n.awsAccessKeyId");
/* 453 */ String SecretAccessKey = conf.get("fs.s3n.awsSecretAccessKey");
/* */ AmazonS3Client s3Client;
/* 455 */ if ((accessKeyId != null) && (SecretAccessKey != null)) {
/* 456 */ s3Client = new AmazonS3Client(new BasicAWSCredentials(accessKeyId, SecretAccessKey));
/* 457 */ LOG.info("Created AmazonS3Client with conf KeyId " + accessKeyId);
/* */ } else {
/* 459 */ InstanceProfileCredentialsProvider provider = new InstanceProfileCredentialsProvider();
/* 460 */ s3Client = new AmazonS3Client(provider);
/* 461 */ LOG.info("Created AmazonS3Client with role keyId " + provider.getCredentials().getAWSAccessKeyId());
/* */ }
/* 463 */ String endpoint = conf.get("fs.s3n.endpoint");
/* 464 */ if ((endpoint == null) && (isGovCloud())) {
/* 465 */ endpoint = "s3-us-gov-west-1.amazonaws.com";
/* */ }
/* 467 */ if (endpoint != null) {
/* 468 */ LOG.info("AmazonS3Client setEndpoint s3-us-gov-west-1.amazonaws.com");
/* 469 */ s3Client.setEndpoint("s3-us-gov-west-1.amazonaws.com");
/* */ }
/* 471 */ return s3Client;
/* */ }
示例10: S3SQSClient
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
public S3SQSClient(Region region, String queueName, String accessKey, String secretKey) {
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setRequestTimeout(5000);
clientConfiguration.setRetryPolicy(new RetryPolicy(null, null, 3, true));
if (accessKey.isEmpty() && secretKey.isEmpty()) {
this.sqs = new AmazonSQSClient(new InstanceProfileCredentialsProvider(), clientConfiguration);
} else {
this.sqs = new AmazonSQSClient(new BasicAWSCredentials(accessKey, secretKey), clientConfiguration);
}
this.sqs.setRegion(region);
this.queueName = queueName;
}
示例11: ApiImporter
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
@SuppressWarnings("deprecation")
public ApiImporter(String profile, String accessKey, String secret) {
if (accessKey != null && secret != null) {
credentialsProvider=new AWSCredentialsProvider() {
@Override
public void refresh() {
}
@Override
public AWSCredentials getCredentials() {
return new AWSCredentials() {
@Override
public String getAWSSecretKey() {
return secret;
}
@Override
public String getAWSAccessKeyId() {
return accessKey;
}
};
}
};
} else {
credentialsProvider = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(profile),
new InstanceProfileCredentialsProvider());
}
amazonApiGatewayClient = new AmazonApiGatewayClient(credentialsProvider);
}
示例12: MyCredentialsProvider
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
MyCredentialsProvider() {
super(new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
// Removed due to ElasticBeanstalk environment not being setup with a profile dir
// new ProfileCredentialsProvider(),
new InstanceProfileCredentialsProvider(),
new ClasspathPropertiesFileCredentialsProvider());
}
示例13: AuthenticationInfoAWSCredentialsProviderChain
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
AuthenticationInfoAWSCredentialsProviderChain(AuthenticationInfo authenticationInfo) {
super(
new InstanceProfileCredentialsProvider(),
new ProfileCredentialsProvider(),
new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
new InstanceProfileCredentialsProvider());
}
開發者ID:lambadaframework,項目名稱:lambadaframework,代碼行數:9,代碼來源:AuthenticationInfoAWSCredentialsProviderChain.java
示例14: init
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
private void init() {
InstanceProfileCredentialsProvider credentialsProvider = new InstanceProfileCredentialsProvider();
AmazonDynamoDB amazonDynamoDB = new AmazonDynamoDBClient(credentialsProvider);
amazonDynamoDB.setRegion(Regions.getCurrentRegion());
dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB, dynamoDBMapperConfig());
amazonS3 = new AmazonS3Client(credentialsProvider);
Region current = Regions.getCurrentRegion();
if (!current.equals(Region.getRegion(Regions.US_EAST_1))) {
amazonS3.setRegion(current);
}
systemUpgrade = new UpgradeSystemTo003();
}
示例15: getCredentials
import com.amazonaws.auth.InstanceProfileCredentialsProvider; //導入依賴的package包/類
/**
*
* @return
*/
private AWSCredentialsProvider getCredentials() {
return new AWSCredentialsProviderChain(new StaticCredentialsProvider(
new AppenderCredentials()), new SystemPropertiesCredentialsProvider(),
new EnvironmentVariableCredentialsProvider(),
new ProfileCredentialsProvider(),
new InstanceProfileCredentialsProvider());
}