-
aws marketplace 연동 , aws credential 자격증명 설정,entitlementsWEB/BACK 2024. 11. 29. 13:38반응형
1. 사전준비 pom.xml
필요한 구성 요소만 가져오기
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.27.9</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>marketplacemetering</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>marketplaceentitlement</artifactId>
</dependency>
1. aws credential 자격증명 설정
final String accessKey = ""; final String secretKey = ""; final String endPoint = ""; final String regionName = "";
@Test public void test() throws Exception { // 자격 증명 설정 AwsBasicCredentials awsCreds = AwsBasicCredentials.create( accessKey, secretKey); // AWS 리전 설정 Region region = Region.AP_EAST_1; // 필요에 따라 리전 변경 가능 // 자격 증명 프로바이더 생성 - 명시적으로 안쓸경우 사용 // ProfileCredentialsProvider credentialsProvider = ProfileCredentialsProvider.create(); // MarketplaceMeteringClient 생성 MarketplaceMeteringClient meteringClient = MarketplaceMeteringClient.builder() .region(region) .credentialsProvider(StaticCredentialsProvider.create(awsCreds)) .build(); // MarketplaceEntitlementClient 생성 MarketplaceEntitlementClient entitlementClient = MarketplaceEntitlementClient.builder() .region(region) .credentialsProvider(StaticCredentialsProvider.create(awsCreds)) .build(); // 임시 토큰을 사용하여 고객 식별 String marketplaceToken = "MJZP+Hm________토큰예시__tLE="; ResolveCustomerResponse customerInfo = resolveCustomer(meteringClient, marketplaceToken); // 고객의 엔타이틀먼트 확인 getEntitlements(entitlementClient, customerInfo.productCode()); // 클라이언트 종료 meteringClient.close(); entitlementClient.close(); } }
2. MarketplaceMeteringClient 의 ResolveCustomer 설정(토큰으로 CustomerIdentifier, CustomerAWSAccountId , ProductCode 획득 과정)
public static ResolveCustomerResponse resolveCustomer(MarketplaceMeteringClient meteringClient, String marketplaceToken) { try { // ResolveCustomerRequest 생성 ResolveCustomerRequest request = ResolveCustomerRequest.builder() .registrationToken(marketplaceToken) .build(); // ResolveCustomer 호출 ResolveCustomerResponse response = meteringClient.resolveCustomer(request); // 응답 처리 System.out.println("Customer Identifier: " + response.customerIdentifier()); System.out.println("Customer AWS Account ID: " + response.customerAWSAccountId()); System.out.println("Product Code: " + response.productCode()); awscusId = response.customerIdentifier(); return response; } catch (MarketplaceMeteringException e) { e.printStackTrace(); System.err.println("ResolveCustomer failed: " + e.awsErrorDetails().errorMessage()); throw e; } }
3. MarketplaceEntitlementClient 의 EntitlementClient 설정(고객의 계약이 유효한지 확인)
public static void getEntitlements(MarketplaceEntitlementClient entitlementClient, String productCode) { try { // filter 설정 (Map<GetEntitlementFilterName, List<String>> 형태) Map<GetEntitlementFilterName, List<String>> filters = new HashMap<>(); filters.put(GetEntitlementFilterName.CUSTOMER_IDENTIFIER, Collections.singletonList(awscusId)); // 실제 customer identifier로 변경 // GetEntitlementsRequest 생성 GetEntitlementsRequest request = GetEntitlementsRequest.builder() .productCode(productCode).filter(filters) .build(); // GetEntitlements 호출 GetEntitlementsResponse response = entitlementClient.getEntitlements(request); // 응답 처리 List<Entitlement> entitlements = response.entitlements(); for (Entitlement entitlement : entitlements) { System.out.println("Entitlement Name dimension: " + entitlement.dimension()); EntitlementValue value = entitlement.value(); if (value.integerValue() != null) { System.out.println("Entitlement Value (Integer): " + value.integerValue()); } else if (value.doubleValue() != null) { System.out.println("Entitlement Value (Double): " + value.doubleValue()); } else if (value.booleanValue() != null) { System.out.println("Entitlement Value (Boolean): " + value.booleanValue()); } else { System.out.println("Entitlement Value (String): " + value.stringValue()); } } } catch (MarketplaceEntitlementException e) { e.printStackTrace(); System.err.println("GetEntitlements failed: " + e.awsErrorDetails().errorMessage()); throw e; } }
entitlement 를 보면 지역이 us-east-1 이라고되어있다.
반응형'WEB > BACK' 카테고리의 다른 글
query DSL 적용방법정리 & 자동 빌드 (0) 2024.11.29 프로젝트에 등록된 모든 oauth-clients 확인 API (0) 2024.11.29 spring cloud config (security) 구현하기 4 (0) 2024.08.01 spring cloud config (server,client,watcher) 구현하기 2 - client server (0) 2024.07.24 spring cloud config (server,client,watcher,java) 구현하기 1 (0) 2024.07.24