@Override public AmazonS3 get() { AmazonS3Client amazonS3 = new AmazonS3Client(awsClusterSecurityManager.getCredentialsProvider()); amazonS3.setRegion(region); return amazonS3; } });
s3Client.setRegion(Region.getRegion(Regions.fromName(region))); s3Client.setEndpoint(endPoint); System.out.println("Connection successfully initialized");
client = new AmazonS3Client(credentials); client.setRegion(s3region.toAWSRegion()); final AmazonS3Client prev = clientsByRegion.putIfAbsent(s3region, client); return prev == null ? client : prev;
@Test public void testSetRegion() { final Regions region = Regions.US_WEST_2; s3.setRegion(Region.getRegion(region)); assertEquals(region.getName(), s3.clientRegion); }
public S3BulkEventStore(Metastore metastore, AWSConfig config, FieldDependencyBuilder.FieldDependency fieldDependency) { this.metastore = metastore; this.config = config; this.s3Client = new AmazonS3Client(config.getCredentials()); s3Client.setRegion(config.getAWSRegion()); if (config.getS3Endpoint() != null) { s3Client.setEndpoint(config.getS3Endpoint()); } kinesis = new AmazonKinesisClient(config.getCredentials()); kinesis.setRegion(config.getAWSRegion()); if (config.getKinesisEndpoint() != null) { kinesis.setEndpoint(config.getKinesisEndpoint()); } cloudWatchClient = new AmazonCloudWatchAsyncClient(config.getCredentials()); cloudWatchClient.setRegion(config.getAWSRegion()); this.conditionalMagicFieldsSize = fieldDependency.dependentFields.size(); }
@Test public void testCreateSignerWithSpecialCharacterKeys() { 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); assertTrue(request.getResourcePath().contains(key)); }
@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); }
BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials( ACCESS_KEY, SECRET_KEY ); AmazonS3Client s3Client = new AmazonS3Client(basicAWSCredentials); s3Client.setEndpoint(ENDPOINT); s3Client.setRegion(Region.getRegion(Regions.EU_WEST_1));; PutObjectRequest por = new PutObjectRequest( "YOUR_BUCKET_NAME", "YOUR_KEY", file); } s3Client.putObject(por);
@Override public S3DataTransferer createDataTransfer() { String bucketName = System.getProperty(BUCKET_NAME_PROPERTY); String region = System.getProperty(REGION_PROPERTY); String accessKey = System.getProperty(ACCESS_KEY_PROPERTY); String secretKey = System.getProperty(SECRET_KEY_PROPERTY); boolean encrypt = Boolean.getBoolean(ENCRYPT_PROPERTY); AmazonS3Client s3 = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey)); s3.setRegion(Region.getRegion(Regions.valueOf(region))); return new S3DataTransferer(s3, bucketName, encrypt); } }
public static AmazonS3Client createS3Client(Region region) { Preconditions.checkNotNull(region); AmazonS3Client s3Client = new AmazonS3Client(getCredentialProvider()); s3Client.setRegion(region); return s3Client; } }
AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey)); s3Client.setRegion(Region.getRegion(Regions.EU_CENTRAL_1)); PutObjectRequest por = new PutObjectRequest(bucketName, folderName + "/" + fileName, new File(filePath)); s3Client.putObject(por); return s3Client.getResourceUrl(bucketName, folderName + "/" + fileName);
@Override public AmazonS3 get() { AmazonS3Client amazonS3 = new AmazonS3Client(awsClusterSecurityManager.getCredentialsProvider()); amazonS3.setRegion(region); return amazonS3; } });
@Override public AmazonS3 get() { AmazonS3Client amazonS3 = new AmazonS3Client(awsClusterSecurityManager.getCredentialsProvider()); amazonS3.setRegion(region); return amazonS3; } });
private static AmazonS3Client newS3Client(String accessKey, String secretKey, com.amazonaws.regions.Region region) { BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); try { AmazonS3Client amazonS3Client = new AmazonS3Client(awsCredentials); if (region != null) { amazonS3Client.setRegion(region); } return amazonS3Client; } catch (AmazonServiceException e) { String err = "Could not create connection to Amazon S3 due " + "to error: " + e.getMessage(); throw new StorageException(err, e, RETRY); } }
private DefaultS3Service(Builder builder) { this.credentials = ImmutableAWSCredentials.copyOf(builder.credentials); this.region = builder.region; this.defaultPermissions = builder.defaultPermissions; this.directoryContentType = builder.directoryContentType; this.automaticRetries = builder.automaticRetries; this.bufferSize = builder.bufferSize; // Setup the client this.client = new AmazonS3Client(credentials); this.client.setRegion(RegionUtils.getRegion(region)); }
@Bean public AmazonS3Client s3Client() { AWSCredentials credentials = new ProfileCredentialsProvider(awsProfileName).getCredentials(); AmazonS3Client s3Client = new AmazonS3Client(credentials); Region region = Region.getRegion(Regions.EU_WEST_1); s3Client.setRegion(region); return s3Client; } }
/** Returns an S3 client given the configuration **/ public static AmazonS3Client getS3Client(Map conf) { AWSCredentialsProvider provider = new DefaultAWSCredentialsProviderChain(); AWSCredentials credentials = provider.getCredentials(); ClientConfiguration config = new ClientConfiguration(); AmazonS3Client client = new AmazonS3Client(credentials, config); String regionName = ConfUtils.getString(conf, REGION); if (StringUtils.isNotBlank(regionName)) { client.setRegion(RegionUtils.getRegion(regionName)); } String endpoint = ConfUtils.getString(conf, ENDPOINT); if (StringUtils.isNotBlank(endpoint)) { client.setEndpoint(endpoint); } return client; }
private void setRegion() { Region region = RegionUtils.getRegion(Regions.fromName(selregion).getName()); getClient().setRegion(region); } }
private AmazonS3 getAmazonS3() { if (amazonS3 == null) { BasicAWSCredentials awsCredentials = new BasicAWSCredentials(getAccessKey(), getSecretKey()); amazonS3 = new AmazonS3Client(awsCredentials); amazonS3.setRegion(Region.getRegion(Regions.fromName(getRegion()))); } return amazonS3; }
public AWSClients(String region, AWSCredentials credentials, String proxyHost, int proxyPort) { this.region = region; this.proxyHost = proxyHost; this.proxyPort = proxyPort; //setup proxy connection: ClientConfiguration clientCfg = new ClientConfiguration(); if (proxyHost != null && proxyPort > 0 ) { clientCfg.setProxyHost(proxyHost); clientCfg.setProxyPort(proxyPort); } this.s3 = credentials != null ? new AmazonS3Client(credentials, clientCfg) : new AmazonS3Client(clientCfg); this.codedeploy = credentials != null ? new AmazonCodeDeployClient(credentials, clientCfg) : new AmazonCodeDeployClient(clientCfg); codedeploy.setRegion(Region.getRegion(Regions.fromName(this.region))); s3.setRegion(Region.getRegion(Regions.fromName(this.region))); }