Example usage for com.amazonaws ClientConfiguration ClientConfiguration

List of usage examples for com.amazonaws ClientConfiguration ClientConfiguration

Introduction

In this page you can find the example usage for com.amazonaws ClientConfiguration ClientConfiguration.

Prototype

public ClientConfiguration() 

Source Link

Usage

From source file:com.netflix.simianarmy.aws.STSAssumeRoleSessionCredentialsProvider.java

License:Apache License

/**
 * Constructs a new STSAssumeRoleSessionCredentialsProvider, which will use
 * the specified long lived AWS credentials to make a request to the AWS
 * Security Token Service (STS), uses the provided {@link #roleArn} to
 * assume a role and then request short lived session credentials, which
 * will then be returned by this class's {@link #getCredentials()} method.
 * @param longLivedCredentials/*from  w ww  .j a v  a2s.  c o  m*/
 *            The main AWS credentials for a user's account.
 * @param roleArn
 *            The AWS ARN of the Role to be assumed.
 */
public STSAssumeRoleSessionCredentialsProvider(AWSCredentials longLivedCredentials, String roleArn) {
    this(longLivedCredentials, roleArn, new ClientConfiguration());
}

From source file:com.netflix.spinnaker.clouddriver.aws.security.AmazonClientProvider.java

License:Apache License

protected <T extends AmazonWebServiceClient> T getClient(Class<T> impl,
        AWSCredentialsProvider awsCredentialsProvider, String region) {
    checkAWSCredentialsProvider(awsCredentialsProvider);
    try {/*from   w w  w  .j ava 2s.c  o m*/
        Constructor<T> constructor = impl.getConstructor(AWSCredentialsProvider.class,
                ClientConfiguration.class);

        ClientConfiguration clientConfiguration = new ClientConfiguration();

        if (awsCredentialsProvider instanceof NetflixSTSAssumeRoleSessionCredentialsProvider) {
            RetryPolicy.RetryCondition delegatingRetryCondition = (originalRequest, exception,
                    retriesAttempted) -> {
                NetflixSTSAssumeRoleSessionCredentialsProvider stsCredentialsProvider = (NetflixSTSAssumeRoleSessionCredentialsProvider) awsCredentialsProvider;
                if (exception instanceof AmazonServiceException) {
                    ((AmazonServiceException) exception).getHttpHeaders().put("targetAccountId",
                            stsCredentialsProvider.getAccountId());
                }
                return retryPolicy.getRetryCondition().shouldRetry(originalRequest, exception,
                        retriesAttempted);
            };

            RetryPolicy delegatingRetryPolicy = new RetryPolicy(delegatingRetryCondition,
                    retryPolicy.getBackoffStrategy(), retryPolicy.getMaxErrorRetry(),
                    retryPolicy.isMaxErrorRetryInClientConfigHonored());
            clientConfiguration.setRetryPolicy(delegatingRetryPolicy);
        } else {
            clientConfiguration.setRetryPolicy(retryPolicy);
        }

        if (proxy != null && proxy.isProxyConfigMode()) {
            proxy.apply(clientConfiguration);
        }

        clientConfiguration.setUseGzip(useGzip);

        T delegate = constructor.newInstance(awsCredentialsProvider, clientConfiguration);
        for (RequestHandler2 requestHandler : requestHandlers) {
            delegate.addRequestHandler(requestHandler);
        }
        if (region != null && region.length() > 0) {
            delegate.setRegion(Region.getRegion(Regions.fromName(region)));
        }
        return delegate;
    } catch (Exception e) {
        throw new RuntimeException("Instantiation of client implementation failed!", e);
    }
}

From source file:com.netflix.spinnaker.echo.pubsub.amazon.SQSSubscriberProvider.java

License:Apache License

@PostConstruct
public void start() {
    if (properties == null) {
        return;/* w ww  .ja  va2 s  .  com*/
    }

    ExecutorService executorService = Executors.newFixedThreadPool(properties.getSubscriptions().size());

    List<PubsubSubscriber> subscribers = new ArrayList<>();

    properties.getSubscriptions().forEach((AmazonPubsubProperties.AmazonPubsubSubscription subscription) -> {
        log.info("Bootstrapping SQS for SNS topic: {}", subscription.getTopicARN());
        if (subscription.getTemplatePath() != null && !subscription.getTemplatePath().equals("")) {
            log.info("Using template: {} for subscription: {}", subscription.getTemplatePath(),
                    subscription.getName());
        }

        ARN queueArn = new ARN(subscription.getQueueARN());

        SQSSubscriber worker = new SQSSubscriber(objectMapper, subscription, pubsubMessageHandler,
                AmazonSNSClientBuilder.standard().withCredentials(awsCredentialsProvider)
                        .withClientConfiguration(new ClientConfiguration()).withRegion(queueArn.getRegion())
                        .build(),
                AmazonSQSClientBuilder.standard().withCredentials(awsCredentialsProvider)
                        .withClientConfiguration(new ClientConfiguration()).withRegion(queueArn.getRegion())
                        .build(),
                () -> enabled.get(), registry);

        try {
            executorService.submit(worker);
            subscribers.add(worker);
            log.debug("Created worker for subscription: {}", subscription.getName());
        } catch (RejectedExecutionException e) {
            log.error("Could not start " + worker.getWorkerName(), e);
        }
    });
    pubsubSubscribers.putAll(subscribers);
}

From source file:com.netflix.spinnaker.echo.pubsub.aws.SQSSubscriberProvider.java

License:Apache License

@PostConstruct
public void start() {
    if (properties == null) {
        return;//  w  w w .  ja v  a2s .  co m
    }

    ExecutorService executorService = Executors.newFixedThreadPool(properties.getSubscriptions().size());

    List<PubsubSubscriber> subscribers = new ArrayList<>();

    properties.getSubscriptions().forEach((AmazonPubsubProperties.AmazonPubsubSubscription subscription) -> {
        log.info("Bootstrapping SQS for SNS topic: {}", subscription.getTopicARN());
        if (subscription.getTemplatePath() != null && !subscription.getTemplatePath().equals("")) {
            log.info("Using template: {} for subscription: {}", subscription.getTemplatePath(),
                    subscription.getName());
        }

        ARN queueArn = new ARN(subscription.getQueueARN());

        SQSSubscriber worker = new SQSSubscriber(objectMapper, subscription, pubsubMessageHandler,
                AmazonSNSClientBuilder.standard().withCredentials(awsCredentialsProvider)
                        .withClientConfiguration(new ClientConfiguration()).withRegion(queueArn.getRegion())
                        .build(),
                AmazonSQSClientBuilder.standard().withCredentials(awsCredentialsProvider)
                        .withClientConfiguration(new ClientConfiguration()).withRegion(queueArn.getRegion())
                        .build(),
                enabled::get, registry, jinjavaFactory, applicationEventPublisher);

        try {
            executorService.submit(worker);
            subscribers.add(worker);
            log.debug("Created worker for subscription: {}", subscription.getName());
        } catch (RejectedExecutionException e) {
            log.error("Could not start " + worker.getWorkerName(), e);
        }
    });
    pubsubSubscribers.putAll(subscribers);
}

From source file:com.netflix.suro.sink.notice.SQSNotice.java

License:Apache License

@JsonCreator
public SQSNotice(@JsonProperty("queues") List<String> queues,
        @JsonProperty("region") @JacksonInject("region") String region,
        @JsonProperty("connectionTimeout") int connectionTimeout,
        @JsonProperty("maxConnections") int maxConnections, @JsonProperty("socketTimeout") int socketTimeout,
        @JsonProperty("maxRetries") int maxRetries,
        @JsonProperty("enableBase64Encoding") boolean enableBase64Encoding,
        @JacksonInject AmazonSQSClient sqsClient, @JacksonInject AWSCredentialsProvider credentialsProvider) {
    this.queues = queues;
    this.region = region;

    this.enableBase64Encoding = enableBase64Encoding;
    this.sqsClient = sqsClient;
    this.credentialsProvider = credentialsProvider;

    Preconditions.checkArgument(queues.size() > 0);
    Preconditions.checkNotNull(region);/*from w  w  w.j a v  a2 s . c  o  m*/

    clientConfig = new ClientConfiguration();
    if (connectionTimeout > 0) {
        clientConfig = clientConfig.withConnectionTimeout(connectionTimeout);
    }
    if (maxConnections > 0) {
        clientConfig = clientConfig.withMaxConnections(maxConnections);
    }
    if (socketTimeout > 0) {
        clientConfig = clientConfig.withSocketTimeout(socketTimeout);
    }
    if (maxRetries > 0) {
        clientConfig = clientConfig.withMaxErrorRetry(maxRetries);
    }

    Monitors.registerObject(Joiner.on('_').join(queues), this);
}

From source file:com.neu.Spark.MainFrame.java

/**
 * Creates new form MainFrame//  w w w.  j av  a 2s.c om
 */
public MainFrame() {
    initComponents();

    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

    ClientConfiguration clientConfig = new ClientConfiguration();
    clientConfig.setProtocol(Protocol.HTTP);

    conn = new AmazonS3Client(credentials);
    conn.setEndpoint("s3.amazonaws.com");

}

From source file:com.nextdoor.bender.aws.S3MockClientFactory.java

License:Apache License

public S3MockClientFactory(int port, String username, String pass) {
    try {//from  w w w  .j ava 2s  .  c  o  m
        this.s3.start(port, username, pass);
    } catch (IOException | InterruptedException | InvalidExitValueException | TimeoutException e) {
        throw new RuntimeException(e);
    }

    BasicAWSCredentials awsCredentials = new BasicAWSCredentials(username, pass);
    this.client = new AmazonS3Client(awsCredentials, new ClientConfiguration());
    this.client.setEndpoint("http://127.0.0.1:" + port);
    this.client.createBucket(S3_BUCKET);
}

From source file:com.nextdoor.bender.ipc.firehose.FirehoseTransportFactory.java

License:Apache License

@Override
public void setConf(AbstractConfig config) {
    this.config = (FirehoseTransportConfig) config;
    this.serializer = new FirehoseTransportSerializer(this.config.getAppendNewline());
    this.client = new AmazonKinesisFirehoseClient(new ClientConfiguration().withGzip(true));

    if (this.config.getRegion() != null) {
        this.client.withRegion(this.config.getRegion());
    }/*  w ww  .j av a2  s.c  o  m*/
}

From source file:com.nike.cerberus.module.CerberusModule.java

License:Apache License

private static <M extends AmazonWebServiceClient> M createAmazonClientInstance(Class<M> clientClass,
        Region region) {//from  ww w .  j  a v a  2 s . c o m
    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 region.createClient(clientClass, chain, new ClientConfiguration());
}

From source file:com.noctarius.hazelcast.aws.HazelcastAwsDiscoveryStrategy.java

License:Open Source License

private AmazonEC2Client buildAmazonEC2Client() {
    ClientConfiguration configuration = new ClientConfiguration();

    // Always set HTTPS as protocol, security first
    configuration.setProtocol(Protocol.HTTPS);

    // Configure proxy configuration
    configureProxy(configuration);/*from  w w w.j a  v a 2  s .co  m*/

    // Configure authentication
    AWSCredentialsProvider credentialsProvider = buildCredentialsProvider();

    // Create WS client
    AmazonEC2Client client = new AmazonEC2Client(credentialsProvider, configuration);

    // Configure Amazon EC2 WS endpoint
    configureEndpoint(client);

    return client;
}