Presigned Json

mail@pastecode.io avatar
unknown
plain_text
8 months ago
848 B
3
Indexable
Never
@GetMapping("/json")
    @ResponseBody
    public Map<String, Object> getJsonFromS3() {
        AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                                .withRegion("your-region")
                                .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY)))
                                .build();

        S3Object s3Object = s3Client.getObject(BUCKET_NAME, OBJECT_KEY);

        ObjectMapper objectMapper = new ObjectMapper();
        Map<String, Object> jsonMap = null;
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(s3Object.getObjectContent()))) {
            jsonMap = objectMapper.readValue(reader, Map.class);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return jsonMap;
    }
Leave a Comment