Java Code Examples for com.amazonaws.client.builder.AwsClientBuilder

The following examples show how to use com.amazonaws.client.builder.AwsClientBuilder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: zfile   Source File: MinIOServiceImpl.java    License: MIT License 7 votes vote down vote up
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
            storageConfigService.selectStorageConfigMapByDriveId(driveId);
    String accessKey = stringStorageConfigMap.get(StorageConfigConstant.ACCESS_KEY).getValue();
    String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue();
    String endPoint = stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue();
    bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue();
    basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true);

    if (Objects.isNull(accessKey) || Objects.isNull(secretKey) || Objects.isNull(endPoint) || Objects.isNull(bucketName)) {
        log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription());
        isInitialized = false;
    } else {
        BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        s3Client = AmazonS3ClientBuilder.standard()
                .withPathStyleAccessEnabled(true)
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "minio")).build();

        testConnection();
        isInitialized = true;
    }
}
 
Example 2
Source Project: camel-kafka-connector   Source File: AWSClientUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static AmazonSNS newSNSClient() {
    LOG.debug("Creating a custom SNS client for running a AWS SNS test");
    AmazonSNSClientBuilder clientBuilder = AmazonSNSClientBuilder
            .standard();

    String awsInstanceType = System.getProperty("aws-service.instance.type");
    String region = getRegion();

    if (awsInstanceType == null || awsInstanceType.equals("local-aws-container")) {
        String amazonHost = System.getProperty(AWSConfigs.AMAZON_AWS_HOST);

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

        clientBuilder
                .withClientConfiguration(clientConfiguration)
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(amazonHost, region))
                .withCredentials(new TestAWSCredentialsProvider("accesskey", "secretkey"));
    } else {
        clientBuilder
                .withRegion(region)
                .withCredentials(new TestAWSCredentialsProvider());
    }

    return clientBuilder.build();
}
 
Example 3
Source Project: Flink-CEPplus   Source File: AWSUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates an Amazon Kinesis Client.
 * @param configProps configuration properties containing the access key, secret key, and region
 * @param awsClientConfig preconfigured AWS SDK client configuration
 * @return a new Amazon Kinesis Client
 */
public static AmazonKinesis createKinesisClient(Properties configProps, ClientConfiguration awsClientConfig) {
	// set a Flink-specific user agent
	awsClientConfig.setUserAgentPrefix(String.format(USER_AGENT_FORMAT,
			EnvironmentInformation.getVersion(),
			EnvironmentInformation.getRevisionInformation().commitId));

	// utilize automatic refreshment of credentials by directly passing the AWSCredentialsProvider
	AmazonKinesisClientBuilder builder = AmazonKinesisClientBuilder.standard()
			.withCredentials(AWSUtil.getCredentialsProvider(configProps))
			.withClientConfiguration(awsClientConfig);

	if (configProps.containsKey(AWSConfigConstants.AWS_ENDPOINT)) {
		// Set signingRegion as null, to facilitate mocking Kinesis for local tests
		builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(
												configProps.getProperty(AWSConfigConstants.AWS_ENDPOINT),
												null));
	} else {
		builder.withRegion(Regions.fromName(configProps.getProperty(AWSConfigConstants.AWS_REGION)));
	}
	return builder.build();
}
 
Example 4
Source Project: flink   Source File: AWSUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates an Amazon Kinesis Client.
 * @param configProps configuration properties containing the access key, secret key, and region
 * @param awsClientConfig preconfigured AWS SDK client configuration
 * @return a new Amazon Kinesis Client
 */
public static AmazonKinesis createKinesisClient(Properties configProps, ClientConfiguration awsClientConfig) {
	// set a Flink-specific user agent
	awsClientConfig.setUserAgentPrefix(String.format(USER_AGENT_FORMAT,
			EnvironmentInformation.getVersion(),
			EnvironmentInformation.getRevisionInformation().commitId));

	// utilize automatic refreshment of credentials by directly passing the AWSCredentialsProvider
	AmazonKinesisClientBuilder builder = AmazonKinesisClientBuilder.standard()
			.withCredentials(AWSUtil.getCredentialsProvider(configProps))
			.withClientConfiguration(awsClientConfig);

	if (configProps.containsKey(AWSConfigConstants.AWS_ENDPOINT)) {
		// Set signingRegion as null, to facilitate mocking Kinesis for local tests
		builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(
												configProps.getProperty(AWSConfigConstants.AWS_ENDPOINT),
												null));
	} else {
		builder.withRegion(Regions.fromName(configProps.getProperty(AWSConfigConstants.AWS_REGION)));
	}
	return builder.build();
}
 
Example 5
Source Project: zfile   Source File: TencentServiceImpl.java    License: MIT License 6 votes vote down vote up
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
            storageConfigService.selectStorageConfigMapByDriveId(driveId);
    String secretId = stringStorageConfigMap.get(StorageConfigConstant.SECRET_ID_KEY).getValue();
    String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue();
    String endPoint = stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue();
    bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue();
    domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue();
    basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true);

    if (Objects.isNull(secretId) || Objects.isNull(secretKey) || Objects.isNull(endPoint) || Objects.isNull(bucketName)) {
        log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription());
        isInitialized = false;
    } else {
        BasicAWSCredentials credentials = new BasicAWSCredentials(secretId, secretKey);
        s3Client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "cos")).build();

        testConnection();
        isInitialized = true;
    }
}
 
Example 6
/**
 * Constructs the driver setting the properties from the properties file using system properties as defaults.
 * Sets the secret cache to the cache that was passed in.
 *
 * @param cache                                             Secret cache to use to retrieve secrets
 */
protected AWSSecretsManagerDriver(SecretCache cache) {

    final Config config = Config.loadMainConfig();

    String vpcEndpointUrl = config.getStringPropertyWithDefault(PROPERTY_PREFIX+"."+PROPERTY_VPC_ENDPOINT_URL, null);
    String vpcEndpointRegion = config.getStringPropertyWithDefault(PROPERTY_PREFIX+"."+PROPERTY_VPC_ENDPOINT_REGION, null);

    if (vpcEndpointUrl == null || vpcEndpointUrl.isEmpty() || vpcEndpointRegion == null || vpcEndpointRegion.isEmpty()) {
        this.secretCache = cache;
    } else {
        AWSSecretsManagerClientBuilder builder = AWSSecretsManagerClientBuilder.standard();
        builder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(vpcEndpointUrl, vpcEndpointRegion));

        this.secretCache = new SecretCache(builder);
    }

    setProperties();
    AWSSecretsManagerDriver.register(this);
}
 
Example 7
Source Project: datacollector   Source File: TestAmazonS3Target.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpClass() throws IOException, InterruptedException {
  File dir = new File(new File("target", UUID.randomUUID().toString()), "fakes3_root").getAbsoluteFile();
  Assert.assertTrue(dir.mkdirs());
  fakeS3Root = dir.getAbsolutePath();
  port = TestUtil.getFreePort();
  fakeS3 = new FakeS3(fakeS3Root, port);
  Assume.assumeTrue("Please install fakes3 in your system", fakeS3.fakes3Installed());
  //Start the fakes3 server
  executorService = Executors.newSingleThreadExecutor();
  executorService.submit(fakeS3);

  BasicAWSCredentials credentials = new BasicAWSCredentials("foo", "bar");
  s3client = AmazonS3ClientBuilder
      .standard()
      .withCredentials(new AWSStaticCredentialsProvider(credentials))
      .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:" + port, null))
      .withPathStyleAccessEnabled(true)
      .withChunkedEncodingDisabled(true) // FakeS3 does not correctly calculate checksums with chunked encoding enabled.
      .build();

  TestUtil.createBucket(s3client, BUCKET_NAME);
  TestUtil.createBucket(s3client, SECOND_BUCKET_NAME);
}
 
Example 8
Source Project: crate   Source File: S3Service.java    License: Apache License 2.0 6 votes vote down vote up
private AmazonS3 buildClient(final S3ClientSettings clientSettings) {
    final AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
    builder.withCredentials(buildCredentials(LOGGER, clientSettings));
    builder.withClientConfiguration(buildConfiguration(clientSettings));

    final String endpoint = Strings.hasLength(clientSettings.endpoint)
        ? clientSettings.endpoint
        : Constants.S3_HOSTNAME;
    LOGGER.debug("using endpoint [{}]", endpoint);

    // If the endpoint configuration isn't set on the builder then the default behaviour is to try
    // and work out what region we are in and use an appropriate endpoint - see AwsClientBuilder#setRegion.
    // In contrast, directly-constructed clients use s3.amazonaws.com unless otherwise instructed. We currently
    // use a directly-constructed client, and need to keep the existing behaviour to avoid a breaking change,
    // so to move to using the builder we must set it explicitly to keep the existing behaviour.
    //
    // We do this because directly constructing the client is deprecated (was already deprecated in 1.1.223 too)
    // so this change removes that usage of a deprecated API.
    builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, null));

    return builder.build();
}
 
Example 9
Source Project: ecs-sync   Source File: AwsS3Test.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    Properties syncProperties = TestConfig.getProperties();
    endpoint = syncProperties.getProperty(TestConfig.PROP_S3_ENDPOINT);
    accessKey = syncProperties.getProperty(TestConfig.PROP_S3_ACCESS_KEY_ID);
    secretKey = syncProperties.getProperty(TestConfig.PROP_S3_SECRET_KEY);
    region = syncProperties.getProperty(TestConfig.PROP_S3_REGION);
    String proxyUri = syncProperties.getProperty(TestConfig.PROP_HTTP_PROXY_URI);
    Assume.assumeNotNull(endpoint, accessKey, secretKey);
    endpointUri = new URI(endpoint);

    ClientConfiguration config = new ClientConfiguration().withSignerOverride("S3SignerType");
    if (proxyUri != null) {
        URI uri = new URI(proxyUri);
        config.setProxyHost(uri.getHost());
        config.setProxyPort(uri.getPort());
    }

    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
            .withClientConfiguration(config)
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region));

    s3 = builder.build();
}
 
Example 10
private GetMediaWorker(Regions region,
        AWSCredentialsProvider credentialsProvider,
        String streamName,
        StartSelector startSelector,
        String endPoint,
        MkvElementVisitor elementVisitor) {
    super(region, credentialsProvider, streamName);

    AmazonKinesisVideoMediaClientBuilder builder = AmazonKinesisVideoMediaClientBuilder.standard()
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, region.getName()))
            .withCredentials(getCredentialsProvider());

    this.videoMedia = builder.build();
    this.elementVisitor = elementVisitor;
    this.startSelector = startSelector;
}
 
Example 11
private ContinuousGetMediaWorker(Regions region,
        AWSCredentialsProvider credentialsProvider,
        String streamName,
        StartSelector startSelector,
        String endPoint,
        GetMediaResponseStreamConsumerFactory consumerFactory) {
    super(region, credentialsProvider, streamName);

    AmazonKinesisVideoMediaClientBuilder builder = AmazonKinesisVideoMediaClientBuilder.standard()
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, region.getName()))
            .withCredentials(getCredentialsProvider());

    this.videoMedia = builder.build();
    this.consumerFactory = consumerFactory;
    this.startSelector = startSelector;
}
 
Example 12
Source Project: zipkin-aws   Source File: AwsClientTracing.java    License: Apache License 2.0 6 votes vote down vote up
public <Builder extends AwsClientBuilder, Client> Client build(
    AwsClientBuilder<Builder, Client> builder
) {
  if (builder == null) throw new NullPointerException("builder == null");
  if (builder instanceof AwsAsyncClientBuilder) {
    ExecutorFactory executorFactory = ((AwsAsyncClientBuilder) builder).getExecutorFactory();
    if (executorFactory == null) {
      ClientConfiguration clientConfiguration = builder.getClientConfiguration();
      if (clientConfiguration == null) {
        clientConfiguration = defaultClientConfigurationFactory.getConfig();
      }
      ((AwsAsyncClientBuilder) builder).setExecutorFactory(
          new TracingExecutorFactory(currentTraceContext, clientConfiguration)
      );
    } else {
      ((AwsAsyncClientBuilder) builder).setExecutorFactory(
          new TracingExecutorFactoryWrapper(currentTraceContext, executorFactory)
      );
    }
  }
  builder.withRequestHandlers(new TracingRequestHandler(httpTracing));
  return builder.build();
}
 
Example 13
Source Project: zipkin-aws   Source File: AwsClientTracingTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
  String endpoint = "http://localhost:" + mockServer.getPort();
  HttpTracing httpTracing = HttpTracing.create(tracing);
  AmazonDynamoDBClientBuilder clientBuilder = AmazonDynamoDBClientBuilder.standard()
      .withCredentials(
          new AWSStaticCredentialsProvider(new BasicAWSCredentials("access", "secret")))
      .withEndpointConfiguration(
          new AwsClientBuilder.EndpointConfiguration(endpoint, "us-east-1"));

  dbClient = AwsClientTracing.create(httpTracing).build(clientBuilder);

  s3Client = AwsClientTracing.create(httpTracing).build(AmazonS3ClientBuilder.standard()
      .withCredentials(
          new AWSStaticCredentialsProvider(new BasicAWSCredentials("access", "secret")))
      .withEndpointConfiguration(
          new AwsClientBuilder.EndpointConfiguration(endpoint, "us-east-1"))
      .enableForceGlobalBucketAccess());
}
 
Example 14
Source Project: flink   Source File: AWSUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates an Amazon Kinesis Client.
 * @param configProps configuration properties containing the access key, secret key, and region
 * @param awsClientConfig preconfigured AWS SDK client configuration
 * @return a new Amazon Kinesis Client
 */
public static AmazonKinesis createKinesisClient(Properties configProps, ClientConfiguration awsClientConfig) {
	// set a Flink-specific user agent
	awsClientConfig.setUserAgentPrefix(String.format(USER_AGENT_FORMAT,
			EnvironmentInformation.getVersion(),
			EnvironmentInformation.getRevisionInformation().commitId));

	// utilize automatic refreshment of credentials by directly passing the AWSCredentialsProvider
	AmazonKinesisClientBuilder builder = AmazonKinesisClientBuilder.standard()
			.withCredentials(AWSUtil.getCredentialsProvider(configProps))
			.withClientConfiguration(awsClientConfig);

	if (configProps.containsKey(AWSConfigConstants.AWS_ENDPOINT)) {
		// If an endpoint is specified, we give preference to using an endpoint and use the region property to
		// sign the request.
		builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(
			configProps.getProperty(AWSConfigConstants.AWS_ENDPOINT),
			configProps.getProperty(AWSConfigConstants.AWS_REGION)));
	} else {
		builder.withRegion(Regions.fromName(configProps.getProperty(AWSConfigConstants.AWS_REGION)));
	}
	return builder.build();
}
 
Example 15
@Bean
public AmazonKinesisAsync amazonKinesis() {
	// See https://github.com/mhart/kinesalite#cbor-protocol-issues-with-the-java-sdk
	System.setProperty(SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY, "true");

	return AmazonKinesisAsyncClientBuilder.standard()
			.withClientConfiguration(
					new ClientConfiguration()
							.withMaxErrorRetry(0)
							.withConnectionTimeout(1000))
			.withEndpointConfiguration(
					new AwsClientBuilder.EndpointConfiguration("http://localhost:" + DEFAULT_KINESALITE_PORT,
							Regions.DEFAULT_REGION.getName()))
			.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("", "")))
			.build();
}
 
Example 16
Source Project: emodb   Source File: AmazonS3Provider.java    License: Apache License 2.0 6 votes vote down vote up
private static AmazonS3 getAmazonS3(final S3BucketConfiguration s3BucketConfiguration, Clock clock) {
    AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder.standard()
            .withCredentials(getAwsCredentialsProvider(s3BucketConfiguration))
            .withAccelerateModeEnabled(s3BucketConfiguration.getAccelerateModeEnabled());
    S3ClientConfiguration.RateLimitConfiguration rateLimitConfiguration = new S3ClientConfiguration.RateLimitConfiguration();
    if (null != s3BucketConfiguration.getRegion()) {
        amazonS3ClientBuilder
                .withRegion(Regions.fromName(s3BucketConfiguration.getRegion()));
    } else if (null != s3BucketConfiguration.getS3ClientConfiguration()) {
        S3ClientConfiguration.EndpointConfiguration endpointConfiguration = s3BucketConfiguration.getS3ClientConfiguration().getEndpointConfiguration();
        amazonS3ClientBuilder
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpointConfiguration.getServiceEndpoint(), endpointConfiguration.getSigningRegion()));
        rateLimitConfiguration = s3BucketConfiguration.getS3ClientConfiguration().getRateLimitConfiguration();
    }
    AmazonS3 amazonS3 = amazonS3ClientBuilder
            .build();

    return new S3RateLimiter(clock, rateLimitConfiguration)
            .rateLimit(amazonS3);
}
 
Example 17
Source Project: aws-doc-sdk-examples   Source File: MoviesDeleteTable.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2"))
            .build();

        DynamoDB dynamoDB = new DynamoDB(client);

        Table table = dynamoDB.getTable("Movies");

        try {
            System.out.println("Attempting to delete table; please wait...");
            table.delete();
            table.waitForDelete();
            System.out.print("Success.");

        }
        catch (Exception e) {
            System.err.println("Unable to delete table: ");
            System.err.println(e.getMessage());
        }
    }
 
Example 18
Source Project: beam   Source File: DefaultS3ClientBuilderFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public AmazonS3ClientBuilder createBuilder(S3Options s3Options) {
  AmazonS3ClientBuilder builder =
      AmazonS3ClientBuilder.standard().withCredentials(s3Options.getAwsCredentialsProvider());

  if (s3Options.getClientConfiguration() != null) {
    builder = builder.withClientConfiguration(s3Options.getClientConfiguration());
  }

  if (!Strings.isNullOrEmpty(s3Options.getAwsServiceEndpoint())) {
    builder =
        builder.withEndpointConfiguration(
            new AwsClientBuilder.EndpointConfiguration(
                s3Options.getAwsServiceEndpoint(), s3Options.getAwsRegion()));
  } else if (!Strings.isNullOrEmpty(s3Options.getAwsRegion())) {
    builder = builder.withRegion(s3Options.getAwsRegion());
  } else {
    LOG.info(
        "The AWS S3 Beam extension was included in this build, but the awsRegion flag "
            + "was not specified. If you don't plan to use S3, then ignore this message.");
  }
  return builder;
}
 
Example 19
Source Project: camel-kafka-connector   Source File: AWSClientUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static AmazonSQS newSQSClient() {
    LOG.debug("Creating a custom SQS client for running a AWS SNS test");
    AmazonSQSClientBuilder clientBuilder = AmazonSQSClientBuilder
            .standard();

    String awsInstanceType = System.getProperty("aws-service.instance.type");
    String region = getRegion();

    if (awsInstanceType == null || awsInstanceType.equals("local-aws-container")) {
        String amazonHost = System.getProperty(AWSConfigs.AMAZON_AWS_HOST);

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

        clientBuilder
                .withClientConfiguration(clientConfiguration)
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(amazonHost, region))
                .withCredentials(new TestAWSCredentialsProvider("accesskey", "secretkey"));
    } else {
        clientBuilder
                .withRegion(region)
                .withCredentials(new TestAWSCredentialsProvider());
    }



    return clientBuilder.build();
}
 
Example 20
@Test
public void testCreateEndpointConfiguration() {
    final AwsClientBuilder.EndpointConfiguration config = CommandLineInterface.createEndpointConfiguration(RegionUtils.getRegion(Regions.US_EAST_1.getName()),
            Optional.<String>absent(), AmazonDynamoDB.ENDPOINT_PREFIX);
    assertTrue(config.getServiceEndpoint().contains("https"));
    assertTrue(config.getServiceEndpoint().contains(AmazonDynamoDB.ENDPOINT_PREFIX));
    assertEquals(Regions.US_EAST_1.getName(), config.getSigningRegion());
}
 
Example 21
Source Project: camel-kafka-connector   Source File: AWSClientUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static AmazonKinesis newKinesisClient() {
    LOG.debug("Creating a new AWS Kinesis client");
    AmazonKinesisClientBuilder clientBuilder = AmazonKinesisClientBuilder.standard();

    String awsInstanceType = System.getProperty("aws-service.kinesis.instance.type");
    String region = getRegion();

    if (awsInstanceType == null || awsInstanceType.equals("local-aws-container")) {
        String amazonHost = System.getProperty(AWSConfigs.AMAZON_AWS_HOST);

        LOG.debug("Creating a new AWS Kinesis client to access {}", amazonHost);

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

        clientBuilder
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(amazonHost, region))
                .withClientConfiguration(clientConfiguration)
                .withCredentials(new TestAWSCredentialsProvider("accesskey", "secretkey"));
    } else {
        clientBuilder
            .withRegion(region)
            .withCredentials(new TestAWSCredentialsProvider());
    }

    return clientBuilder.build();
}
 
Example 22
@Override
public AWSGlue newClient() throws MetaException {
  try {
    AWSGlueClientBuilder glueClientBuilder = AWSGlueClientBuilder.standard()
        .withCredentials(getAWSCredentialsProvider(conf));

    String regionStr = getProperty(AWS_REGION, conf);
    String glueEndpoint = getProperty(AWS_GLUE_ENDPOINT, conf);

    // ClientBuilder only allows one of EndpointConfiguration or Region to be set
    if (StringUtils.isNotBlank(glueEndpoint)) {
      logger.info("Setting glue service endpoint to " + glueEndpoint);
      glueClientBuilder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(glueEndpoint, null));
    } else if (StringUtils.isNotBlank(regionStr)) {
      logger.info("Setting region to : " + regionStr);
      glueClientBuilder.setRegion(regionStr);
    } else {
      Region currentRegion = Regions.getCurrentRegion();
      if (currentRegion != null) {
        logger.info("Using region from ec2 metadata : " + currentRegion.getName());
        glueClientBuilder.setRegion(currentRegion.getName());
      } else {
        logger.info("No region info found, using SDK default region: us-east-1");
      }
    }

    glueClientBuilder.setClientConfiguration(buildClientConfiguration(conf));
    return glueClientBuilder.build();
  } catch (Exception e) {
    String message = "Unable to build AWSGlueClient: " + e;
    logger.error(message);
    throw new MetaException(message);
  }
}
 
Example 23
Source Project: micronaut-aws   Source File: AWSLambdaConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param endpointConfiguration The {@link AwsClientBuilder#getEndpoint()}
 */
@Inject
public void setEndpointConfiguration(@Nullable AwsClientBuilder.EndpointConfiguration endpointConfiguration) {
    if (endpointConfiguration != null) {
        builder.setEndpointConfiguration(endpointConfiguration);
    }
}
 
Example 24
private AmazonDynamoDB buildDynamoDbClient(Regions region) {
    return AmazonDynamoDBClientBuilder.standard()
            .withEndpointConfiguration(
                    new AwsClientBuilder.EndpointConfiguration(DYNAMODB_LOCAL_ENDPOINT,
                            region.getName()))
            .build();
}
 
Example 25
Source Project: wecube-platform   Source File: RealS3Client.java    License: Apache License 2.0 5 votes vote down vote up
public RealS3Client(String endpoint, String accessKey, String secretKey) {
    ClientConfiguration clientConfiguration = new ClientConfiguration();
    clientConfiguration.setSignerOverride("AWSS3V4SignerType");
    AmazonS3 newClient = AmazonS3ClientBuilder.standard()
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, Regions.US_EAST_1.name()))
            .withPathStyleAccessEnabled(true)
            .withClientConfiguration(clientConfiguration)
            .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
            .build();
    this.s3Client = newClient;
    this.endpoint = endpoint;
}
 
Example 26
Source Project: wecube-platform   Source File: S3BucketManagementService.java    License: Apache License 2.0 5 votes vote down vote up
public AmazonS3 newS3Client(String host, String port, String username, String password) {
    String endPoint = String.format("http://%s:%s", host, port);
    ClientConfiguration clientConfiguration = new ClientConfiguration();
    return AmazonS3ClientBuilder.standard()
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, Regions.US_EAST_1.name()))
            .withPathStyleAccessEnabled(true)
            .withClientConfiguration(clientConfiguration)
            .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(username, password)))
            .build();
}
 
Example 27
Source Project: zfile   Source File: HuaweiServiceImpl.java    License: MIT License 5 votes vote down vote up
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
            storageConfigService.selectStorageConfigMapByDriveId(driveId);
    String accessKey = stringStorageConfigMap.get(StorageConfigConstant.ACCESS_KEY).getValue();
    String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue();
    String endPoint = stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue();

    bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue();
    domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue();
    basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true);

    if (Objects.isNull(accessKey) || Objects.isNull(secretKey) || Objects.isNull(endPoint) || Objects.isNull(bucketName)) {
        log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription());
        isInitialized = false;
    } else {
        BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        s3Client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "obs")).build();

        testConnection();
        isInitialized = true;
    }
}
 
Example 28
Source Project: zfile   Source File: S3ServiceImpl.java    License: MIT License 5 votes vote down vote up
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
            storageConfigService.selectStorageConfigMapByDriveId(driveId);
    String accessKey = stringStorageConfigMap.get(StorageConfigConstant.ACCESS_KEY).getValue();
    String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue();
    String endPoint = stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue();

    super.domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue();
    super.basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    super.bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue();
    super.isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true);

    String pathStyle = stringStorageConfigMap.get(StorageConfigConstant.PATH_STYLE).getValue();

    boolean isPathStyle = "path-style".equals(pathStyle);

    if (Objects.isNull(accessKey) || Objects.isNull(secretKey) || Objects.isNull(endPoint) || Objects.isNull(bucketName)) {
        log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription());
        isInitialized = false;
    } else {
        BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        s3Client = AmazonS3ClientBuilder.standard()
                .withPathStyleAccessEnabled(isPathStyle)
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "")).build();

        testConnection();
        isInitialized = true;
    }
}
 
Example 29
Source Project: zfile   Source File: AliyunServiceImpl.java    License: MIT License 5 votes vote down vote up
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
        storageConfigService.selectStorageConfigMapByDriveId(driveId);
    String accessKey = stringStorageConfigMap.get(StorageConfigConstant.ACCESS_KEY).getValue();
    String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue();
    String endPoint = stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue();

    super.domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue();
    super.basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    super.bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue();
    super.isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true);

    if (Objects.isNull(accessKey) || Objects.isNull(secretKey) || Objects.isNull(endPoint) || Objects.isNull(bucketName)) {
        log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription());
        isInitialized = false;
    } else {
        BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

        super.s3Client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "oss")).build();
        testConnection();
        isInitialized = true;
    }
}
 
Example 30
Source Project: zfile   Source File: QiniuServiceImpl.java    License: MIT License 5 votes vote down vote up
@Override
public void init(Integer driveId) {
    this.driveId = driveId;
    Map<String, StorageConfig> stringStorageConfigMap =
            storageConfigService.selectStorageConfigMapByDriveId(driveId);
    String accessKey = stringStorageConfigMap.get(StorageConfigConstant.ACCESS_KEY).getValue();
    String secretKey = stringStorageConfigMap.get(StorageConfigConstant.SECRET_KEY).getValue();
    String endPoint =  stringStorageConfigMap.get(StorageConfigConstant.ENDPOINT_KEY).getValue();

    bucketName = stringStorageConfigMap.get(StorageConfigConstant.BUCKET_NAME_KEY).getValue();
    domain = stringStorageConfigMap.get(StorageConfigConstant.DOMAIN_KEY).getValue();
    basePath = stringStorageConfigMap.get(StorageConfigConstant.BASE_PATH).getValue();
    isPrivate = Convert.toBool(stringStorageConfigMap.get(StorageConfigConstant.IS_PRIVATE).getValue(), true);

    if (Objects.isNull(accessKey) || Objects.isNull(secretKey) || Objects.isNull(endPoint) || Objects.isNull(bucketName)) {
        log.debug("初始化存储策略 [{}] 失败: 参数不完整", getStorageTypeEnum().getDescription());
        isInitialized = false;
    } else {
        BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        s3Client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, "kodo")).build();

        testConnection();
        isInitialized = true;
    }
}