일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- springboot
- 맛집
- Oracle
- MySQL
- ubuntu
- jenkins
- tool
- devops
- elasticsearch
- javascript
- php
- Design Patterns
- IntelliJ
- AWS
- jsp
- Git
- Gradle
- JVM
- db
- Spring
- linux
- Spring Batch
- Web Server
- 요리
- ReactJS
- java
- it
- Spring Boot
- laravel
- redis
Archives
- Today
- Total
아무거나
[aws-java-sdk] S3 Bucket 조회 본문
반응형
// s3 bucket 가져오기
@Repository
public class S3BucketService {
private static String bucketName = "deploy.versioning";
private static String bucketFolderRoot = "project";
private static String accessKey = {accesskey};
private static String key = {key};
@Autowired
private ProjectDAOServiceImpl deployDAOService;
// 전체 버킷 조회 서비스 모델
public HashMap<String, ArrayList<String>> getS3Bucket() {
ArrayList<String> projectArr = new ArrayList<String>();
HashMap<String, ArrayList<String>> dataMap = new HashMap<String, ArrayList<String>>();
AWSCredentials crd = new BasicAWSCredentials(accessKey, key);
AmazonS3 s3Client = new AmazonS3Client(crd);
try {
ObjectListing bucketObject = s3Client.listObjects(bucketName, "project");
// objectSummary 는 s3 버킷객체
for (S3ObjectSummary objectSummary : bucketObject.getObjectSummaries()) {
String[] keyArr = objectSummary.getKey().split("/");
if(keyArr.length == 2) {
projectArr.add(keyArr[1]);
}
}
dataMap.put("data", projectArr);
} catch(AmazonServiceException ase) {
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
}
return dataMap;
}
}
// 버킷 프로젝트별 서비스 모델
public HashMap<String, HashMap<String, ArrayList<String>>> getS3BucketVersion(String projectName, String bucketType) throws ParseException {
HashMap<String, HashMap<String, ArrayList<String>>> dataMap = new HashMap<String, HashMap<String, ArrayList<String>>>();
HashMap<String, ArrayList<String>> buildMap = new HashMap<String, ArrayList<String>>();
ArrayList<String> devBuildArr = new ArrayList<String>();
ArrayList<String> qaBuildArr = new ArrayList<String>();
ArrayList<String> liveBuildArr = new ArrayList<String>();
AWSCredentials crd = new BasicAWSCredentials(accessKey, key);
AmazonS3 s3Client = new AmazonS3Client(crd);
String bucketFolderName = bucketFolderRoot + "/" + projectName;
try {
ObjectListing objects = s3Client.listObjects(bucketName, bucketFolderName);
for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
if(objectSummary.getSize() > 0) {
String[] keyArr = objectSummary.getKey().split("/");
// live current version date put
if (keyArr[2].equals("develop")) { // chatbot
devBuildArr.add(keyArr[3]);
buildMap.put(keyArr[2], devBuildArr);
} else if (keyArr[2].equals("dev")) {
devBuildArr.add(keyArr[3]);
buildMap.put(keyArr[2], devBuildArr);
} else if (keyArr[2].equals("qa")) {
qaBuildArr.add(keyArr[3]);
buildMap.put(keyArr[2], qaBuildArr);
} else {
liveBuildArr.add(keyArr[3]);
buildMap.put(keyArr[2], liveBuildArr);
}
} // size end if
} // end for
dataMap.put("data", buildMap);
} catch(AmazonServiceException ase) {
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
}
return dataMap;
}
반응형
'Infra > AWS' 카테고리의 다른 글
elasticcache 도입 사례 및 사용법 (0) | 2019.12.24 |
---|---|
[aws-sdk-java] s3에 파일업로드하기 (0) | 2019.06.24 |
[cloudsearch] cloudsearch 무한 processing -> 최근상품 리스트표시X (0) | 2019.03.27 |
[codedeploy] 트리거 설정(aws sns 알람) (0) | 2019.03.21 |
[codepipeline] codepipeline에서 s3연동시 주의사항 및 요금 (0) | 2019.03.21 |
Comments