Java용 를 AWS Marketplace Metering Service 사용하여 컨테이너 제품을 AWS SDK와 통합 - AWS Marketplace

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Java용 를 AWS Marketplace Metering Service 사용하여 컨테이너 제품을 AWS SDK와 통합

다음 예제에서는 를 사용하여 AWS Marketplace 측정 서비스 MeterUsage 작업과 AWS SDK for Java 통합하는 구현을 간략하게 설명합니다. 자세한 내용은 MeterUsage Java 예제 섹션을 참조하세요. 아래 단계 중 대부분은 언어에 상관없이 적용됩니다.

예: AWS Marketplace Metering Service 통합
  1. AWS Marketplace Management Portal에 로그인합니다.

  2. 자산에서 컨테이너를 선택하여 새 컨테이너 제품 생성을 시작합니다. 제품을 만들면 제품에 대한 제품 코드가 생성되어 컨테이너 이미지와 통합할 수 있습니다. AWS Identity and Access Management (IAM) 권한 설정에 대한 자세한 내용은 섹션을 참조하세요AWS Marketplace 계량 및 권한 부여 API 권한.

  3. 퍼블릭 AWS Java SDK를 다운로드합니다.

    중요

    Amazon Elastic Kubernetes Service(Amazon EKS)에서 측정 API 작업을 호출하려면 지원되는 를 사용하고 AWS SDK Kubernetes 1.13 이상을 실행하는 Amazon EKS 클러스터에서 실행해야 합니다.

  4. 각 차원 사용에 대해 1시간마다 작업 또는 포드에서 MeterUsage 작업을 호출합니다. API 작업은 Dimension, Resource및 의 고유한 조합에 대한 하나의 측정 레코드를 허용합니다Hour. 리소스는 Amazon Elastic Container Service(AmazonECS) 태스크 또는 Amazon EKS 포드입니다.

    { "ProductCode" : "string", // (required) "UsageDimension" : "string", // (required) "UsageQuantity": int, // (optional) Default is 0. Acceptable value from [0, 2147483647 (INT_MAX)] "Timestamp": Date, // (required) Timestamp in UTC. Value can be one hour in the past. "UsageAllocations": List<UsageAllocation> // (optional) UsageAllocations across 1 or more tags. }
    참고

    에 연결할 때 일시적인 문제가 발생할 수 AWS Marketplace Metering Service있습니다. AWS Marketplace 단기 중단 또는 네트워크 문제를 방지하려면 지수를 다시 끈 상태에서 최대 30분 동안 재시도를 구현하는 것이 좋습니다.

  5. MeterUsage 호출을 포함하는 컨테이너 이미지의 새 버전을 다시 빌드하고, 컨테이너에 태그를 지정하고EKS, Amazon Elastic Container Registry(Amazon)와 같이 Amazon ECS 또는 Amazon 와 호환되는 모든 Docker 레지스트리로 푸시합니다ECR. Amazon 를 사용하는 경우 ECRAmazon ECS 태스크 또는 Amazon 포드를 시작하는 계정에 Amazon EKS ECR리포지토리에 대한 권한이 있는지 확인합니다. 그렇지 않으면 작업이 실패합니다.

  6. 다음 코드 예제에 정의된 MeterUsage대로 컨테이너가 를 호출할 수 있는 권한을 부여하는 IAM 역할을 생성합니다. Amazon 태스크 또는 Amazon 포드 정의의 태스크 역할 파라미터에 이 AWS Identity and Access Management (IAM) 역할을 제공해야 합니다. ECS EKS

    { "Version": "2012-10-17", "Statement": [ { "Action": [ "aws-marketplace:MeterUsage" ], "Effect": "Allow", "Resource": "*" } ] }
  7. 와 통합된 컨테이너를 참조 AWS Marketplace 하고 EKS 6단계에서 생성한 IAM 역할을 참조하는 Amazon ECS 작업 또는 Amazon 포드 정의를 생성합니다. 로깅을 보려면 작업 정의에서 AWS CloudTrail 로깅을 활성화합니다.

  8. Amazon ECS 또는 Amazon EKS 클러스터를 생성하여 작업 또는 포드를 실행합니다. Amazon ECS 클러스터 생성에 대한 자세한 내용은 Amazon Elastic Container Service 개발자 안내서클러스터 생성을 참조하세요. Amazon EKS 클러스터 생성(Kubernetes 버전 1.1.3.x 이상 사용)에 대한 자세한 내용은 Amazon EKS 클러스터 생성을 참조하세요.

  9. Amazon ECS 또는 Amazon EKS 클러스터를 구성하고 us-east-1 AWS 리전의 8단계에서 생성한 Amazon ECS 작업 정의 또는 Amazon EKS 포드를 시작합니다. 제품이 라이브 상태가 되기 전에 이 테스트 프로세스 중에만 이 리전을 사용해야 합니다.

  10. 제품에 대해 게시되는 차원마다 MeterUsage에서 유효한 응답을 받으면 컨테이너 제품 생성을 시작할 수 있습니다. 궁금한 점은 AWS Marketplace 판매자 작업 팀에 문의하십시오.

MeterUsage Java 예제

다음 코드 예제에서는 AWS SDK for Java 및 AWS Marketplace 측정 서비스를 사용하여 MeterUsage 작업을 호출합니다.

다음은 UsageAllocations 없이 MeterUsage 작업을 호출하는 코드 예제입니다.

import com.amazonaws.services.marketplacemetering.AWSMarketplaceMetering; import com.amazonaws.services.marketplacemetering.AWSMarketplaceMeteringClientBuilder; import com.amazonaws.services.marketplacemetering.model.MeterUsageRequest; import com.amazonaws.services.marketplacemetering.model.MeterUsageResult; import java.util.Date; public class MeterUsage { private static final String PRODUCT_CODE = "......."; private final AWSMarketplaceMetering awsMarketplaceMetering; public MeterUsage() { awsMarketplaceMetering = AWSMarketplaceMeteringClientBuilder.standard().build(); } /** * Submits metering record for a FCP Dimension. The API accepts 1 metering record per dimension * for a given buyer's resource for a given timestamp hour. Ex. If a buyer is running 10 tasks, * the API will accepts 1 call to MeterUsage in an hour for a given dimension for each running task. * * @param dimension - FCP dimension name provided during the publishing of the product. * @param quantity - FCP dimension consumption value for the hour. * @param timestamp - Timestamp, in UTC, for which the usage is being reported. * Timestamp cant be more than 1 hour in the past. * Make sure the timestamp value is not before the start of the software usage. */ public void callMeterUsage(String dimension, int quantity, Date timestamp) { MeterUsageRequest meterUsageRequest = new MeterUsageRequest() .withProductCode(PRODUCT_CODE) .withUsageDimension(dimension) .withUsageQuantity(quantity) .withTimestamp(timestamp); MeterUsageResult meterUsageResult = awsMarketplaceMetering.meterUsage(meterUsageRequest); } }

다음은 UsageAllocations를 사용하여 MeterUsage 작업을 호출하는 코드 예제입니다.

private static String callMeterUsageWithAllocationsByTag(AWSMarketplaceMetering marketplaceMetering) { // Tag Keys for the product String tagKey1 = "Key1"; String tagKey2 = "Key2"; String tagKey3 = "Key3"; // 1st Usage Allocation bucket which has two Tags [{Key1, Key1Value1},{Key2, Key2Value1}] List<Tag> tagsForUsageAllocation1 = Arrays.asList(new Tag().withKey(tagKey1).withValue("Key1Value1"), new Tag().withKey(tagKey2).withValue("Key2Value1")); UsageAllocation usageAllocation1 = new UsageAllocation() .withTags(tagsForUsageAllocation1) .withAllocatedUsageQuantity(20); // 2nd Usage Allocation bucket which has two Tags [{Key1, Key1Value2},{Key2, Key2Value1}] List<Tag> tagsForUsageAllocation2 = Arrays.asList(new Tag().withKey(tagKey1).withValue("Key1Value2"), new Tag().withKey(tagKey2).withValue("Key2Value1")); UsageAllocation usageAllocation2 = new UsageAllocation() .withTags(tagsForUsageAllocation2) .withAllocatedUsageQuantity(20); // 3rd Usage Allocation bucket which has two Tags [{Key1, Key1Value2},{Key2, Key2Value2},{Key3, Key3Value1}] List<Tag> tagsForUsageAllocation3 = Arrays.asList(new Tag().withKey(tagKey1).withValue("Key1Value2"), new Tag().withKey(tagKey2).withValue("Key2Value2"), new Tag().withKey(tagKey3).withValue("Key3Value1")); UsageAllocation usageAllocation3 = new UsageAllocation() .withTags(tagsForUsageAllocation3) .withAllocatedUsageQuantity(15); // 4th Usage Allocation bucket with no tags UsageAllocation usageAllocation4 = new UsageAllocation() .withAllocatedUsageQuantity(15); List<UsageAllocation> usageAllocationList = Arrays.asList(usageAllocation1, usageAllocation2, usageAllocation3, usageAllocation4); MeterUsageRequest meterUsageRequest = new MeterUsageRequest() .withProductCode("TestProductCode") .withUsageDimension("Dimension1") .withTimestamp(new Date()) //UsageQuantity value must match with sum of all AllocatedUsageQuantity .withUsageQuantity(70) .withUsageAllocations(usageAllocationList); MeterUsageResult meterUsageResult; try { meterUsageResult = marketplaceMetering.meterUsage(meterUsageRequest); } catch (Exception e) { // Log Error throw e; } return meterUsageResult.getMeteringRecordId(); }