如何从 aws-marketplace 调用 ResolveCustomer 和 GetEntitlements?

How to call ResolveCustomer and GetEntitlements from aws-marketplace?

我找到了 java sdk 但我找不到用法示例。

我需要调用 ResolveCustomer(为产品和用户生成令牌)和 GetEntitlements(为产品和用户提供权限列表)。

有人用过这个服务吗?

这里是从 aws marketplace 获取客户信息的完整示例。 你应该使用这个库:

 <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-marketplacemeteringservice</artifactId>
            <version>1.11.192</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-marketplaceentitlement</artifactId>
            <version>1.11.194</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>

Java 代码:

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.marketplaceentitlement.AWSMarketplaceEntitlementClient;
import com.amazonaws.services.marketplaceentitlement.AWSMarketplaceEntitlementClientBuilder;
import com.amazonaws.services.marketplaceentitlement.model.GetEntitlementsRequest;
import com.amazonaws.services.marketplaceentitlement.model.GetEntitlementsResult;
import com.amazonaws.services.marketplacemetering.*;
import com.amazonaws.services.marketplacemetering.model.*;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class R
{
    @Test
    public void test() throws Exception
    {
        AWSCredentialsProvider provider = new AWSCredentialsProvider()
        {
            public AWSCredentials getCredentials()
            {
                return new AWSCredentials()
                {
                    public String getAWSAccessKeyId()
                    {
                        return "<YOUR ACCESS KEY>";
                    }

                    public String getAWSSecretKey()
                    {
                        return "YOUR SECRET KEY";
                    }
                };
            }

            public void refresh()
            {

            }
        };


        AWSMarketplaceMeteringClientBuilder b = AWSMarketplaceMeteringClient.builder();
        b.setRegion("us-east-1");  // YOUR AWS REGION
        b.setCredentials(provider);
        AWSMarketplaceMetering c = b.build();

        ResolveCustomerRequest r = new ResolveCustomerRequest();
        r.setRegistrationToken(<YOUR "x-amzn-marketplace-token">); // it comes to your application in the url parameter when the user clicks the buy button in the aws market
        final ResolveCustomerResult response = c.resolveCustomer(r);


        AWSMarketplaceEntitlementClientBuilder entitlementClientBuilder = AWSMarketplaceEntitlementClient.builder();
        entitlementClientBuilder.setRegion("us-east-1");
        entitlementClientBuilder.setCredentials(provider);

        GetEntitlementsRequest getEntitlementsRequest = new GetEntitlementsRequest();
        getEntitlementsRequest.setProductCode(response.getProductCode());

        getEntitlementsRequest.setFilter(new HashMap<String, List<String>>()
        {{
            put("CUSTOMER_IDENTIFIER", new ArrayList<String>()
            {{
                add(response.getCustomerIdentifier());
            }});
        }});
        GetEntitlementsResult entitlementsResult = entitlementClientBuilder.build().getEntitlements(getEntitlementsRequest);
        entitlementsResult = null;
    }
}

您还应该在您的 aws 帐户中添加策略: