3
I have an application here in Java that uses the Amazon SDK to send images to a Bucket S3.
To do this I use threads, basically it is modeled as follows:
The class Mai
n has a thread list and each item in the list is sent to a Executor class and this calls a class Callable
that downloads an image and returns the image information to the image uploader.
The problem that every time I send the image I have to connect to Bucket. Look:
BasicAWSCredentials credentials = new BasicAWSCredentials("Usuario", "Senha");
AmazonS3 s3client = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(Regions.US_EAST_1).build();
Can anyone tell me a way to instantiate these connecting objects in the Main
for when I arrive at the Executor
when sending I am already connected?
You are running the local application or is it an EC2 instance?
– Tom Melo
The application I spin from my own machine.
– Andre
Configure your credentials on the machine, hence you do not need to be informing user and password hard coded. And if you’re going to upload your application to an EC2 setting, just give S3 access permission via IAM.
– Tom Melo
But even so I will have to connect every time. What I need is to perform this connect operation only once.
– Andre
Ah understood... Just you pass the instance of the Amazons3 class to your executing class. Define a constructor in the executing class that takes an argument of type Amazons3, likely to solve.
– Tom Melo
You can’t use a Singleton? (although I think keeping a connection open is a bad idea)
– igventurelli
@Igorventurelli It can! There is no "connection" open, it is just an Http Request without Keep Alive.
– Tom Melo
User and password are fixed?
– Victor Stafusa
They are fixed, thanks for the reply friend, soon I will try here!
– Andre