Refine search
clientConfig.setMaxConnections(Integer.parseInt(maxConnections)); s3Client = new AmazonS3Client(s3Credentials, clientConfig); s3Client.setRegion(Region.getRegion(Regions.fromName(region))); s3Client.setEndpoint(endPoint); System.out.println("Connection successfully initialized"); } catch (Exception e){
/** * Sets the region to be used for the default AWS SDK metric collector; * or null if the default is to be used. */ public static void setRegion(Regions region) { AwsSdkMetrics.region = RegionUtils.getRegion(region.getName()); }
clientBuilder = AmazonS3Client.builder() .withCredentials(credentialsProvider) .withClientConfiguration(clientConfig) Region region = Regions.getCurrentRegion(); if (region != null) { clientBuilder = clientBuilder.withRegion(region.getName()); regionOrEndpointSet = true;
/** * Returns a region enum corresponding to the given region name. * * @param regionName * The name of the region. Ex.: eu-west-1 * @return Region enum representing the given region name. */ public static Regions fromName(String regionName) { for (Regions region : Regions.values()) { if (region.getName().equals(regionName)) { return region; } } throw new IllegalArgumentException("Cannot create enum from " + regionName + " value!"); }
protected static AllowableValue createAllowableValue(final Regions region) { return new AllowableValue(region.getName(), region.getDescription(), "AWS Region Code : " + region.getName()); }
private AmazonS3 getS3Client() throws Exception{ this.bucketName = properties.getProperty( "usergrid.binary.bucketname" ); if(bucketName == null){ logger.error( "usergrid.binary.bucketname not properly set so amazon bucket is null" ); throw new AwsPropertiesNotFoundException( "usergrid.binary.bucketname" ); } final UsergridAwsCredentialsProvider ugProvider = new UsergridAwsCredentialsProvider(); AWSCredentials credentials = ugProvider.getCredentials(); ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setProtocol(Protocol.HTTP); s3Client = new AmazonS3Client(credentials, clientConfig); if(regionName != null) s3Client.setRegion( Region.getRegion(Regions.fromName(regionName)) ); return s3Client; }
|| StringUtils.isNullOrEmpty(secretKey)) { LOG.info("Configuring Amazon Client from environment"); s3service = new AmazonS3Client(getClientConfiguration(prop)); } else { LOG.info("Configuring Amazon Client from property file."); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); s3service = new AmazonS3Client(credentials, getClientConfiguration(prop)); } else { if (StringUtils.isNullOrEmpty(region)) { com.amazonaws.regions.Region s3Region = Regions.getCurrentRegion(); if (s3Region != null) { region = s3Region.getName(); } else { throw new AmazonClientException( s3service.setEndpoint(endpoint); LOG.info("S3 service endpoint [{}] ", endpoint); return s3service;
clientOptions.setPathStyleAccess(false); this.amazonS3Client = new AmazonS3Client(credentials, clientConfig); if (StringUtils.isNotEmpty(s3ReaderConfiguration.getRegion())) { this.amazonS3Client.setRegion(Region.getRegion(Regions.fromName(s3ReaderConfiguration.getRegion()))); this.amazonS3Client.setS3ClientOptions(clientOptions);
s3Service = new AmazonS3Client(awsCredentials); Regions regions = Regions.fromName(awsRegionName); Region region = Region.getRegion(regions); s3Service.setRegion(region); log.info("S3 Region set to: " + region.getName()); } catch (IllegalArgumentException e) { log.warn("Invalid aws_region: " + awsRegionName);
/** * Returns the region configured for the default AWS SDK metric collector; * or null if the default is to be used. * * @throws IllegalArgumentException when using a region not included in * {@link Regions} * * @deprecated Use {@link #getRegionName()} */ public static Regions getRegion() throws IllegalArgumentException { return Regions.fromName(region.getName()); }
private static AmazonS3 getAmazonS3Client(AuditWriterConfiguration configuration) { AWSCredentialsProvider credentialsProvider; if (configuration.getS3AccessKey() != null && configuration.getS3SecretKey() != null) { credentialsProvider = new StaticCredentialsProvider( new BasicAWSCredentials(configuration.getS3AccessKey(), configuration.getS3SecretKey())); } else { credentialsProvider = new DefaultAWSCredentialsProviderChain(); } AmazonS3 s3 = new AmazonS3Client(credentialsProvider) .withRegion(Regions.fromName(configuration.getLogBucketRegion())); if (configuration.getS3Endpoint() != null) { s3.setEndpoint(configuration.getS3Endpoint()); } return s3; }
/** * Determine region. If not specified tries to determine region from where the * application is running or fall back to the default. * * @return Region to configure the client */ private Region findRegion() { boolean regionProvided = !Validator.isBlank(this.region); if(!regionProvided) { // Determine region from where application is running, or fall back to default region Region currentRegion = Regions.getCurrentRegion(); if(currentRegion != null) { return currentRegion; } return Region.getRegion(Regions.fromName(AppenderConstants.DEFAULT_REGION)); } return Region.getRegion(Regions.fromName(this.region)); }
private URI getCreateBucketEndpoint(String requestRegion) { // Route to the default endpoint if they're not trying to specify a different one in the request. if(requestRegion == null || requestRegion.equals(clientRegion) || !clientOptions.isForceGlobalBucketAccessEnabled()) { return endpoint; } // If they enabled global bucket access and they're trying to create a bucket in a region different than the default // one specified when they created the client, it will probably fail because only us-east-1 (actually the global // endpoint) is capable of creating buckets outside of its region. Override the endpoint to which the request // is routed so that it will succeed. com.amazonaws.regions.Region targetRegion = com.amazonaws.regions.Region.getRegion(Regions.fromName(requestRegion)); return new DefaultServiceEndpointBuilder(getEndpointPrefix(), clientConfiguration.getProtocol().toString()).withRegion(targetRegion) .getServiceEndpoint(); }
@Test public void testCreateSigner() { s3.setS3ClientOptions(accelerateOption); final Regions region = Regions.US_WEST_2; s3.setRegion(Region.getRegion(region)); final String bucketName = "bucket"; final String key = "key"; final HttpMethodName method = HttpMethodName.GET; final GetObjectRequest originalRequest = new GetObjectRequest(bucketName, key); final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method); final Signer signer = s3.createSigner(request, bucketName, key); assertTrue(signer instanceof AWSS3V4Signer); signer.sign(request, creds); final String authorization = request.getHeaders().get("Authorization"); assertNotNull(authorization); final String regionName = authorization.split("/")[2]; assertEquals(region.getName(), regionName); }
/** * Setter for Jackson to deserialize Regions enum from string * * @param region */ public void setRegion(String region) { this.region = Regions.fromName(region); } }
@Provides @Singleton protected Region provideAmazonRegion() { return Objects.firstNonNull(Regions.getCurrentRegion(), Region.getRegion(Regions.US_EAST_1)); }
tmpRegion = regionProvider.getRegion(); } catch (final SdkClientException e) { tmpRegion = Regions.getCurrentRegion() != null ? Regions.getCurrentRegion().getName() : Regions.US_EAST_1.getName(); log.warn( "Couldn't determine the AWS region from the provider ({}) supplied. Defaulting to {}", ); this.defaultRegion = Regions.fromName(tmpRegion);