Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- S3AsyncClient client = S3AsyncClient.create();
- final CompletableFuture<GetObjectResponse> futureGet =
- client.getObject(
- GetObjectRequest.builder()
- .bucket(awsS3Config.getBucketName())
- .key(finalKeyName)
- .build(),
- AsyncResponseHandler.toFile(Paths.get(s3TmpFile.getAbsolutePath())));
- futureGet.whenComplete((resp, err) -> {
- try {
- if (resp != null) {
- System.out.println(resp);
- } else {
- // Handle error
- err.printStackTrace();
- }
- } finally {
- // Lets the application shut down. Only close the client when you are completely done with it
- FunctionalUtils.invokeSafely(client::close);
- }
- });
- if (ENVIRONMENT_LOCAL)
- {
- ClientConfiguration clientConfig = new ClientConfiguration();
- clientConfig.setProtocol(Protocol.HTTP);
- clientConfig.setProxyHost(8888);
- //Attempt to connect using Access Key and SecretKey
- BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(awsS3Config.getIamKey(), awsS3Config.getIamSecretKey());
- clientConfig.setProxyHost("myproxyhost.bla");
- clientConfig.setProxyPort(8888);
- AWSStaticCredentialsProvider
- awsStaticCredentialsProvider =
- new AWSStaticCredentialsProvider(basicAWSCredentials);
- this.amazonS3 = AmazonS3ClientBuilder.standard()
- .withRegion(awsS3Config.getRegion())
- .withClientConfiguration(clientConfig)
- .withCredentials(awsStaticCredentialsProvider)
- .build();
- }
- else //not local env, use EC2 instance authentication
- {
- this.amazonS3 = AmazonS3ClientBuilder.standard()
- .withRegion(awsS3Config.getRegion())
- .withCredentials(new
- InstanceProfileCredentialsProvider(false))
- .build();
- }
Add Comment
Please, Sign In to add comment