I'm trying to download a JSON file from an AWS S3 bucket through Java.
The file is created by a 3rd party billing application called Zuora.
The first step is to use OAuth credentials to generate the file. I then get a response with the file URL. I can access this via the browser and download it to my desktop, but when I try to process the file via Java I'm running into issues.
Everywhere I look online I see that people seem to have overcome similar issues by using AmazonS3Client from the AWS libraries. Ref: AWS S3 Java SDK - Download file help
I've tried this but as I'm accessing the bucket via a 3rd party I don't have the Auth ID & Secret to create credentials to make the call.
Do I need these credentials to do a GET call to a bucket on AWS S3? I'm thinking I shouldn't as I'm not trying to create a file or a bucket etc. I haven't been able to download the file via java without credentials.
Below I've added the URL that I'm trying to download the file from and the Java code.
Zuora response with URL: { "data": { "id": "fec47238-6a0f-48ef-9fb2-c7e24da886d5", "query": "select i.AccountId, i.Amount, i.PostedDate, i.InvoiceNumber, i.Status, i.Id from Invoice i, Subscription s where i.Status = 'Posted' and i.Amount > 0 and i.AccountId = s.AccountId and s.Id = '8ad084a67d58433a017d5cd0682c0b89'", "useIndexJoin": false, "sourceData": "LIVE", "queryStatus": "completed", "dataFile": "**https://bucket-name.s3.us-west-2.amazonaws.com/file-name.jsonl?X-Amz-Security-Token=some-tokenX-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20211215T110928Z&X-Amz-SignedHeaders=host&X-Amz-Expires=14400&X-Amz-Credential=Some-Credential&X-Amz-Signature=some-Signature**", "outputRows": 1, "processingTime": 1918, "remainingRetries": 3, "retries": 3, "updatedOn": "2021-12-15T11:09:28.123Z", "createdBy": "some-id" }
2 Java:
private final AmazonS3 amazonS3Client = AmazonS3ClientBuilder.standard().withRegion(Regions.US_WEST_2).build();
try (final S3Object s3Object = amazonS3Client.getObject("bucket-name.s3.us-west-2.amazonaws.com",
"file-name.jsonl");
final InputStreamReader streamReader = new InputStreamReader(s3Object.getObjectContent(), StandardCharsets.UTF_8);
final BufferedReader reader = new BufferedReader(streamReader)) {
System.out.println(reader.lines().collect(Collectors.toSet()));
}
Error: com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied;