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; }
/** * 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()); }
@SdkTestInternalApi SnsMessageManager(String region, SignatureVerifier signatureVerifier) { this.endpoint = RegionUtils.getRegion(region).getServiceEndpoint(AmazonSNS.ENDPOINT_PREFIX); this.signatureVerifier = signatureVerifier; this.messageUnmarshaller = new SnsMessageUnmarshaller(client); }
@Override public URI getServiceEndpoint() { String serviceEndpoint = region.getServiceEndpoint(serviceName); if (serviceEndpoint == null) { serviceEndpoint = String.format("%s.%s.%s", serviceName, region.getName(), region.getDomain()); log.info("{" + serviceName + ", " + region.getName() + "} was not " + "found in region metadata, trying to construct an " + "endpoint using the standard pattern for this region: '" + serviceEndpoint + "'."); } return toURI(stripProtocol(serviceEndpoint)); }
AWSCredentialsProvider provider; ClientConfiguration clientConfiguration = new ClientConfiguration(); boolean isHttpProxyEnabled = mConfig.getAwsProxyEnabled(); String httpProxyHost = mConfig.getAwsProxyHttpHost(); int httpProxyPort = mConfig.getAwsProxyHttpPort(); clientConfiguration.setProxyHost(httpProxyHost); clientConfiguration.setProxyPort(httpProxyPort); client = new AmazonS3Client(provider, clientConfiguration); client.setEndpoint(endpoint); } else if (!region.isEmpty()) { client.setRegion(Region.getRegion(Regions.fromName(region)));
System.out.println("Inizializing the S3 connection"); s3Credentials = new BasicAWSCredentials(accessKeyId, secretKey); clientConfig = new ClientConfiguration(); clientConfig.setMaxErrorRetry(Integer.parseInt(maxErrorRetry)); if(protocol.equals("HTTP")) { clientConfig.setProtocol(Protocol.HTTP); } else { clientConfig.setProtocol(Protocol.HTTPS); 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){
private AmazonS3Client createS3Client(Configuration conf) { AWSCredentialsProvider credentials; String accessKey = conf.get(ConfigurationParameters.ACCESS_KEY_PARAM); String secretKey = conf.get(ConfigurationParameters.SECRET_KEY_PARAM); if (accessKey != null || secretKey != null) { // Keys explicitly configured checkArgument(accessKey != null && secretKey != null, "Access and secret keys must both be provided"); credentials = new StaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)); } else { // Use the default provider chain credentials = new DefaultAWSCredentialsProviderChain(); } String regionParam = conf.get(ConfigurationParameters.REGION_PARAM); Region region = Region.getRegion(regionParam != null ? Regions.fromName(regionParam) : DEFAULT_REGION); AmazonS3Client s3 = new AmazonS3Client(credentials); s3.setRegion(region); return s3; }
/** * Constructs a user-pool with default {@link ClientConfiguration}. * * @param context REQUIRED: Android application context. * @param awsConfiguration REQUIRED: Holds the configuration read from awsconfiguration.json */ public CognitoUserPool(Context context, AWSConfiguration awsConfiguration) { try { final JSONObject userPoolConfiguration = awsConfiguration.optJsonObject("CognitoUserPool"); this.context = context; this.userPoolId = userPoolConfiguration.getString("PoolId"); this.clientId = userPoolConfiguration.getString("AppClientId"); this.clientSecret = userPoolConfiguration.optString("AppClientSecret"); this.pinpointEndpointId = CognitoPinpointSharedContext.getPinpointEndpoint(context, userPoolConfiguration.optString("PinpointAppId")); final ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setUserAgent(awsConfiguration.getUserAgent()); this.client = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), clientConfig); this.client.setRegion(com.amazonaws.regions.Region.getRegion(Regions.fromName(userPoolConfiguration.getString("Region")))); } catch (Exception e) { throw new IllegalArgumentException("Failed to read PoolId, AppClientId, " + "AppClientSecret, or Region from AWSConfiguration please check your setup " + "or awsconfiguration.json file", e); } }
@Override public void setup(Context.OperatorContext context) { s3client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey)); if (region != null) { s3client.setRegion(Region.getRegion(Regions.fromName(region))); } filePath = context.getValue(DAG.APPLICATION_PATH); try { fs = FileSystem.newInstance(new Path(filePath).toUri(), new Configuration()); } catch (IOException e) { logger.error("Unable to create FileSystem: {}", e.getMessage()); } super.setup(context); }
/** * Returns an instance of this object with default settings and configured to talk to the * {@link Regions#DEFAULT_REGION}. * * @deprecated The default region set by this constructor is subject to change. Use the builder method to construct * instances of this class for better control. */ @Deprecated public KmsMasterKeyProvider(final AWSCredentialsProvider creds) { this(creds, Region.getRegion(Regions.DEFAULT_REGION), new ClientConfiguration(), Collections .<String> emptyList()); }
ClientConfiguration clientConfiguration = new ClientConfiguration() .withMaxErrorRetry(maxErrorRetries) .withProtocol(sslEnabled ? Protocol.HTTPS : Protocol.HTTP) .withConnectionTimeout(toIntExact(connectTimeout.toMillis())) .withSocketTimeout(toIntExact(socketTimeout.toMillis())) RequestMetricCollector metricCollector = new PrestoS3FileSystemMetricCollector(stats); AWSCredentialsProvider awsCredentialsProvider = getAwsCredentialsProvider(config, defaults); AmazonS3Builder<? extends AmazonS3Builder, ? extends AmazonS3> clientBuilder = AmazonS3Client.builder() .withCredentials(awsCredentialsProvider) .withClientConfiguration(clientConfiguration) Region region = Regions.getCurrentRegion(); if (region != null) { clientBuilder.withRegion(region.getName()); regionOrEndpointSet = true;
/** * Convenient method for setting region. * * @param region region to set to; must not be null. * * @see #setRegion(Region) * @deprecated use {@link AwsClientBuilder#setRegion(String)} */ @Deprecated public final void configureRegion(Regions region) { checkMutability(); if (region == null) throw new IllegalArgumentException("No region provided"); this.setRegion(Region.getRegion(region)); }
@Test public void testInstantiateClientNoCredentials() { final Region usEast1 = Region.getRegion(Regions.US_EAST_1); final ClientConfiguration conf = new ClientConfiguration(); conf.setConnectionTimeout(5); final AmazonServiceClient asc = usEast1.createClient(AmazonServiceClient.class, null, conf); assertNotNull(asc); assertSame(asc.conf, conf); assertNull(asc.provider); }
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(); }
private static AWSGlueAsync createAsyncGlueClient(GlueHiveMetastoreConfig config) { ClientConfiguration clientConfig = new ClientConfiguration().withMaxConnections(config.getMaxGlueConnections()); AWSGlueAsyncClientBuilder asyncGlueClientBuilder = AWSGlueAsyncClientBuilder.standard() .withClientConfiguration(clientConfig); if (config.getGlueRegion().isPresent()) { asyncGlueClientBuilder.setRegion(config.getGlueRegion().get()); } else if (config.getPinGlueClientToCurrentRegion()) { Region currentRegion = Regions.getCurrentRegion(); if (currentRegion != null) { asyncGlueClientBuilder.setRegion(currentRegion.getName()); } } return asyncGlueClientBuilder.build(); }
@Test public void testInstantiateClient() { final Region usEast1 = Region.getRegion(Regions.US_EAST_1); final AWSCredentialsProvider prov = new AWSCredentialsProvider() { @Override public AWSCredentials getCredentials() { return null; } @Override public void refresh() { } }; final ClientConfiguration conf = new ClientConfiguration(); final AmazonServiceClient asc = usEast1.createClient(AmazonServiceClient.class, prov, conf); assertNotNull(asc); assertSame(asc.provider, prov); assertSame(asc.conf, conf); }
@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); }