Search in sources :

Example 1 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider in project cas by apereo.

the class DynamoDbCloudConfigBootstrapConfiguration method getAmazonDynamoDbClient.

private static AmazonDynamoDB getAmazonDynamoDbClient(final Environment environment) {
    final ClientConfiguration cfg = new ClientConfiguration();
    try {
        final String localAddress = getSetting(environment, "localAddress");
        if (StringUtils.isNotBlank(localAddress)) {
            cfg.setLocalAddress(InetAddress.getByName(localAddress));
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    final String key = getSetting(environment, "credentialAccessKey");
    final String secret = getSetting(environment, "credentialSecretKey");
    final AWSCredentials credentials = new BasicAWSCredentials(key, secret);
    String region = getSetting(environment, "region");
    if (StringUtils.isBlank(region)) {
        region = Regions.getCurrentRegion().getName();
    }
    String regionOverride = getSetting(environment, "regionOverride");
    if (StringUtils.isNotBlank(regionOverride)) {
        regionOverride = Regions.getCurrentRegion().getName();
    }
    final String endpoint = getSetting(environment, "endpoint");
    final AmazonDynamoDB client = AmazonDynamoDBClient.builder().withCredentials(new AWSStaticCredentialsProvider(credentials)).withClientConfiguration(cfg).withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, regionOverride)).withRegion(region).build();
    return client;
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 2 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider in project quickutil by quickutil.

the class AWSS3Util method buildClient.

/**
 * 获取客户端实例
 *
 * @param s3Name-S3Name
 * @return
 */
public static AmazonS3 buildClient(String s3Name) {
    AmazonS3ClientBuilder s3Builder = AmazonS3ClientBuilder.standard();
    s3Builder.setCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(bucketMap.get(s3Name).get("access_key"), bucketMap.get(s3Name).get("secret_key"))));
    s3Builder.setEndpointConfiguration(new EndpointConfiguration(bucketMap.get(s3Name).get("endpoint"), bucketMap.get(s3Name).get("region")));
    return s3Builder.build();
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 3 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider in project opennms by OpenNMS.

the class DefaultAmazonSQSManager method createSQSClient.

private AmazonSQS createSQSClient() {
    final AmazonSQSClientBuilder builder = AmazonSQSClientBuilder.standard().withRegion(sqsConfig.getRegion());
    if (sqsConfig.hasStaticCredentials()) {
        final BasicAWSCredentials awsCreds = new BasicAWSCredentials(sqsConfig.getAccessKey(), sqsConfig.getSecretKey());
        builder.withCredentials(new AWSStaticCredentialsProvider(awsCreds));
    }
    if (sqsConfig.isUseHttp()) {
        final ClientConfiguration clientConfig = new ClientConfiguration();
        clientConfig.setProtocol(Protocol.HTTP);
        builder.withClientConfiguration(clientConfig);
    }
    return builder.build();
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonSQSClientBuilder(com.amazonaws.services.sqs.AmazonSQSClientBuilder) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 4 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider in project jointware by isdream.

the class EC2Main method main.

/**
 * @param args
 */
public static void main(String[] args) {
    AWSCredentials ac = new BasicAWSCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET);
    AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(ac);
    AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().withRegion(Regions.AP_NORTHEAST_1).withCredentials(credentialsProvider).build();
    System.out.println(ec2.getClass().getName());
// for (com.amazonaws.services.ec2.model.Region region : ec2.describeRegions().getRegions()) {
// System.out.println(region.getRegionName());
// }
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 5 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider in project sic by belluccifranco.

the class AmazonServiceImpl method getSessionCredentials.

private Credentials getSessionCredentials() {
    BasicAWSCredentials creds = new BasicAWSCredentials(accessKeyId, accessKeySecret);
    AWSSecurityTokenService sts = AWSSecurityTokenServiceClientBuilder.standard().withRegion(this.region).withCredentials(new AWSStaticCredentialsProvider(creds)).build();
    GetSessionTokenRequest getSessionTokenRequest = new GetSessionTokenRequest().withDurationSeconds(43200);
    sessionCredentials = sts.getSessionToken(getSessionTokenRequest).getCredentials();
    return sessionCredentials;
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) GetSessionTokenRequest(com.amazonaws.services.securitytoken.model.GetSessionTokenRequest) AWSSecurityTokenService(com.amazonaws.services.securitytoken.AWSSecurityTokenService) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Aggregations

AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)72 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)51 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)16 AWSCredentials (com.amazonaws.auth.AWSCredentials)15 ClientConfiguration (com.amazonaws.ClientConfiguration)13 Test (org.junit.Test)12 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)11 SdkClientException (com.amazonaws.SdkClientException)10 AmazonS3 (com.amazonaws.services.s3.AmazonS3)10 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)9 AmazonClientException (com.amazonaws.AmazonClientException)8 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)8 Regions (com.amazonaws.regions.Regions)8 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)8 Test (org.junit.jupiter.api.Test)7 File (java.io.File)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)5 AWSLambda (com.amazonaws.services.lambda.AWSLambda)4 Segment (com.amazonaws.xray.entities.Segment)4