-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAwsConfig.java
More file actions
90 lines (75 loc) · 3.62 KB
/
AwsConfig.java
File metadata and controls
90 lines (75 loc) · 3.62 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.blockcloud.config;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.costexplorer.CostExplorerClient;
/**
* AWS 설정 클래스
* AWS Cost Explorer API 클라이언트를 설정합니다.
*/
@Slf4j
@Configuration
@ConfigurationProperties(prefix = "aws")
@Getter
@Setter
public class AwsConfig {
private Credentials credentials;
private String region;
@Getter
@Setter
public static class Credentials {
private String accessKeyId;
private String secretAccessKey;
}
@Bean
public CostExplorerClient costExplorerClient() {
log.info("Initializing AWS Cost Explorer Client...");
try {
// AWS 자격 증명 검증
if (credentials == null) {
log.error("AWS credentials configuration is missing");
throw new IllegalArgumentException("AWS credentials configuration is missing");
}
String accessKeyId = credentials.getAccessKeyId();
String secretAccessKey = credentials.getSecretAccessKey();
log.info("AWS Access Key ID: {}", accessKeyId != null ? accessKeyId.substring(0, Math.min(8, accessKeyId.length())) + "..." : "null");
if (accessKeyId == null || accessKeyId.trim().isEmpty()) {
log.error("AWS Access Key ID is missing or empty");
throw new IllegalArgumentException("AWS Access Key ID is missing or empty");
}
if (secretAccessKey == null || secretAccessKey.trim().isEmpty()) {
log.error("AWS Secret Access Key is missing or empty");
throw new IllegalArgumentException("AWS Secret Access Key is missing or empty");
}
// 기본값 체크 (플레이스홀더 값들)
if ("your-access-key".equals(accessKeyId) ||
"your-secret-key".equals(secretAccessKey) ||
"AKIAXXXXXXXXXXXXXXXX".equals(accessKeyId) ||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".equals(secretAccessKey)) {
log.error("Please configure valid AWS credentials in application.yml");
throw new IllegalArgumentException("Please configure valid AWS credentials in application.yml");
}
log.info("Creating AWS Basic Credentials...");
AwsBasicCredentials awsCredentials = AwsBasicCredentials.create(
accessKeyId.trim(),
secretAccessKey.trim()
);
log.info("Building Cost Explorer Client...");
CostExplorerClient client = CostExplorerClient.builder()
.region(Region.US_EAST_1) // Cost Explorer는 us-east-1만 지원
.credentialsProvider(StaticCredentialsProvider.create(awsCredentials))
.build();
log.info("AWS Cost Explorer Client initialized successfully");
return client;
} catch (Exception e) {
log.error("Failed to initialize AWS Cost Explorer Client: {}", e.getMessage(), e);
throw new RuntimeException("Failed to initialize AWS Cost Explorer Client", e);
}
}
}