Refine search
public AmazonS3 getS3Client( VariableSpace space ) throws SdkClientException { if ( !getUseAwsDefaultCredentials() ) { // Handle legacy credentials ( embedded in the step ). We'll force a region since it not specified and // then turn on GlobalBucketAccess so if the files accessed are elsewhere it won't matter. BasicAWSCredentials credentials = new BasicAWSCredentials( Encr.decryptPasswordOptionallyEncrypted( space.environmentSubstitute( awsAccessKey ) ), Encr.decryptPasswordOptionallyEncrypted( space.environmentSubstitute( awsSecretKey ) ) ); return AmazonS3ClientBuilder.standard() .withCredentials( new AWSStaticCredentialsProvider( credentials ) ) .withRegion( Regions.US_EAST_1 ) .enableForceGlobalBucketAccess() .build(); } else { // Get Credentials the new way return AmazonS3ClientBuilder.standard() .enableForceGlobalBucketAccess() .build(); } } }
@Provides @LazySingleton public ServerSideEncryptingAmazonS3 getAmazonS3Client( AWSCredentialsProvider provider, AWSProxyConfig proxyConfig, AWSEndpointConfig endpointConfig, AWSClientConfig clientConfig, S3StorageConfig storageConfig ) { final ClientConfiguration configuration = new ClientConfigurationFactory().getConfig(); final Protocol protocol = determineProtocol(clientConfig, endpointConfig); final AmazonS3ClientBuilder builder = AmazonS3Client .builder() .withCredentials(provider) .withClientConfiguration(setProxyConfig(configuration, proxyConfig).withProtocol(protocol)) .withChunkedEncodingDisabled(clientConfig.isDisableChunkedEncoding()) .withPathStyleAccessEnabled(clientConfig.isEnablePathStyleAccess()) .withForceGlobalBucketAccessEnabled(clientConfig.isForceGlobalBucketAccessEnabled()); if (StringUtils.isNotEmpty(endpointConfig.getUrl())) { builder.setEndpointConfiguration( new EndpointConfiguration(endpointConfig.getUrl(), endpointConfig.getSigningRegion()) ); } return new ServerSideEncryptingAmazonS3(builder.build(), storageConfig.getServerSideEncryption()); }
@Test public void s3Test() throws IOException { AmazonS3 s3 = AmazonS3ClientBuilder .standard() .withEndpointConfiguration(localstack.getEndpointConfiguration(S3)) .withCredentials(localstack.getDefaultCredentialsProvider()) .build(); s3.createBucket("foo"); s3.putObject("foo", "bar", "baz"); final List<Bucket> buckets = s3.listBuckets(); assertEquals("The created bucket is present", 1, buckets.size()); final Bucket bucket = buckets.get(0); assertEquals("The created bucket has the right name", "foo", bucket.getName()); assertEquals("The created bucket has the right name", "foo", bucket.getName()); final ObjectListing objectListing = s3.listObjects("foo"); assertEquals("The created bucket has 1 item in it", 1, objectListing.getObjectSummaries().size()); final S3Object object = s3.getObject("foo", "bar"); final String content = IOUtils.toString(object.getObjectContent(), Charset.forName("UTF-8")); assertEquals("The object can be retrieved", "baz", content); } }
/** * Builds an amazon S3 client * * @return */ private AmazonS3 s3Client() { AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(regionName()) // The first region to // try your request // against .build(); return s3; }
/** * @return Create new instance of builder with all defaults set. */ public static AmazonS3ClientBuilder standard() { return new AmazonS3ClientBuilder().withCredentials(new S3CredentialsProviderChain()); }
AmazonS3 s3 = AmazonS3ClientBuilder.standard().build(); Region usWest2 = com.amazonaws.regions.Region.getRegion(Regions.US_WEST_2); s3.setRegion(usWest2); s3.createBucket(bucketName); for (Bucket bucket : s3.listBuckets()) { System.out.println(" - " + bucket.getName());
AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withRegion(getAwsRegion()) .build(); ObjectMetadata metaData = s3Client.getObjectMetadata(bucketName, key); S3Object existingContent = s3Client.getObject(bucketName, key); int i; s3Client.putObject(request);
clientConfig.getApacheHttpClientConfig().withSslSocketFactory(sf); AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard().withClientConfiguration(clientConfig); if (config.hasAttribute("default-bucket-location")) { String bl = config.getAttribute("default-bucket-location"); System.out.println("bucketLocation=" + bucketLocation.toString()); builder = builder.withRegion(bl); } else if (s3Target != null) { EndpointConfiguration ep = new EndpointConfiguration(s3Target, "us-east-1"); builder = builder.withEndpointConfiguration(ep); System.out.println("target=" + s3Target); } else { String bl = "us-west-2"; System.out.println("bucketLocation=" + bl); builder = builder.withRegion(bl); builder = builder.withCredentials(new AWSStaticCredentialsProvider(awsCredentials)); else builder = builder.withCredentials(new InstanceProfileCredentialsProvider(false)); builder.withPathStyleAccessEnabled(Boolean.parseBoolean(config.getAttribute("disableDNSBucket"))); System.out.println("disableDNSBucket=" + Boolean.parseBoolean(config.getAttribute("disableDNSBucket"))); s3Service = builder.build();
log.info("uploading uber jar"); AmazonS3ClientBuilder s3builder = AmazonS3ClientBuilder.standard(); s3builder.withRegion(region); s3builder.withCredentials(getCredentialsProvider()); AmazonS3 s3Client = s3builder.build(); if (!s3Client.doesBucketExist(bucketName)) { s3Client.createBucket(bucketName); s3Client.putObject(new PutObjectRequest(bucketName, uberJarFile.getName(), uberJarFile));
private void loadConfig(String region, String bucket, String key) { log_.info("Loading config from region: " + region + " bucket: " + bucket + " key: " + key); AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withRegion(region) .build(); S3Object s3object = s3Client.getObject(new GetObjectRequest(bucket, key)); try(S3ObjectInputStream in = s3object.getObjectContent()) { loadConfig(in); } catch (IOException e) { log_.warn("Failed to close config input", e); } }
@Inject public S3FileSystem( @Named("awss3roleassumption") IS3Credential cred, Provider<AbstractBackupPath> pathProvider, ICompression compress, final IConfiguration config, BackupMetrics backupMetrics, BackupNotificationMgr backupNotificationMgr, InstanceInfo instanceInfo) { super(pathProvider, compress, config, backupMetrics, backupNotificationMgr); s3Client = AmazonS3Client.builder() .withCredentials(cred.getAwsCredentialProvider()) .withRegion(instanceInfo.getRegion()) .build(); }
.orElse(System.getenv(S3_REGION_PROPERTY)); final AmazonS3 s3client = StringUtils.isNotBlank(region) ? AmazonS3ClientBuilder.standard().withRegion(region).build() : AmazonS3ClientBuilder.defaultClient(); final List<S3ObjectSummary> conversationScripts = s3client.listObjects(listRequest).getObjectSummaries().stream() .filter(os -> os.getKey().toLowerCase().endsWith(".yml")).collect(Collectors.toList()); log.info("[INFO] Load conversation script file " + conversationScript.getKey() + " from S3 bucket " + bucket); AlexaClient.create(s3client.getObject(bucket, conversationScript.getKey()).getObjectContent()) .build() .startScript();
(ConfigurationContext.ConfigurationProperties.AWS_S3_BUCKET_NAME); AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withCredentials(new PropertiesFileCredentialsProvider(configFilePath.toString())) .withRegion(clientRegion) .build(); ObjectListing objectListing = s3Client.listObjects(bucketName, s3KeyName); List<S3ObjectSummary> objectSummaries = objectListing.getObjectSummaries(); logger.debug(StringUtil.concatStrings("deleting file", os.getKey(), "of test plan ", testPlan.getId())); s3Client.deleteObject(new DeleteObjectRequest(bucketName, os.getKey())); s3Client.deleteObject(new DeleteObjectRequest(bucketName, s3KeyName)); return true; } catch (AmazonServiceException e) {
String region = args[1]; s3 = AmazonS3ClientBuilder.standard() .withCredentials(new ProfileCredentialsProvider()) .withRegion(region) .build(); if (s3.doesBucketExistV2(bucket_name)) { System.out.format("\nCannot create the bucket. \n" + "A bucket named '%s' already exists.", bucket_name); try { System.out.format("\nCreating a new bucket named '%s'...\n\n", bucket_name); s3.createBucket(new CreateBucketRequest(bucket_name, region)); } catch (AmazonS3Exception e) { System.err.println(e.getErrorMessage()); s3.deleteBucket(bucket_name); } catch (AmazonS3Exception e) { System.err.println(e.getErrorMessage());
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(Common.getInstance().getAWSCredentials())).build(); if (!AWSS3Utils.doesBucketExist(s3Client, s3BucketName)) { s3Client.createBucket(s3BucketName); s3Client.putObject(new PutObjectRequest(s3BucketName, awsFileName, new File(FOKLogger.getLogFilePathAndName()))); FOKLogger.info(ReportingDialog.class.getName(), "Upload completed"); } catch (AmazonServiceException ase) { AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(Common.getInstance().getAWSCredentialsProvider()).build(); if (!AWSS3Utils.doesBucketExist(s3Client, s3BucketName)) { s3Client.createBucket(s3BucketName);
@Override public void initialize() throws RRepositoryException { AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard(); if (!StringUtils.isBlank(accessKey) && !StringUtils.isBlank(secretKey)) { builder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey))); } else { builder.withCredentials(new DefaultAWSCredentialsProviderChain()); s3 = builder.withRegion(Regions.fromName(regionName)).build(); if (!s3.doesBucketExist(bucketName)) { s3.createBucket(bucketName); String status = s3.getBucketVersioningConfiguration(bucketName).getStatus(); if (!BucketVersioningConfiguration.ENABLED.equals(status)) { try {
/** * Creates an {@link AmazonS3} client instance that is configured to call the started S3Mock * server using HTTPS for a given region. * * @param region Region to define regional endpoint. * * @return The {@link AmazonS3} instance. */ public AmazonS3 createS3Client(final String region) { final BasicAWSCredentials credentials = new BasicAWSCredentials("foo", "bar"); return AmazonS3ClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(credentials)) .withClientConfiguration( configureClientToIgnoreInvalidSslCertificates(new ClientConfiguration())) .withEndpointConfiguration(getEndpointCongiguration(region)) .enablePathStyleAccess() .build(); }
if (s3Client == null) { if (awsCredentialsProvider != null) { s3Client = AmazonS3ClientBuilder.standard().withCredentials(awsCredentialsProvider) .build(); } else { s3Client = AmazonS3ClientBuilder.standard().build(); = s3Client.getObject(new GetObjectRequest(s3path.bucket, s3path.key)); final BufferedReader reader = new BufferedReader(new InputStreamReader(s3object.getObjectContent()));
public AmazonS3 getS3client() { BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, securityKey); if (testing && (!testingUrl.isEmpty() || !testingUrl.equals(""))) { s3client = new AmazonS3Client(awsCreds); s3client.setRegion(Region.getRegion(Regions.fromName(bucketRegion))); s3client.setEndpoint(testingUrl); s3client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).disableChunkedEncoding().build()); } else { s3client = AmazonS3ClientBuilder.standard().withRegion(Regions.fromName(bucketRegion)) .withCredentials(new AWSStaticCredentialsProvider(awsCreds)).build(); } return s3client; }