aws-java-sdkaws-marketplace

How to call ResolveCustomer and GetEntitlements from aws-marketplace?


I found the Java package but I can't find a usage example.

I need to call ResolveCustomer (produces a token for the product and user) and GetEntitlements (gives a list of rights for the product and the user).

Has anyone used this service?


Solution

  • Here is full example to get information about client from AWS marketplace. You should to use these libraries:

     <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 code:

    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;
        }
    }
    

    Also you should add this policy in your AWS account:

    enter image description here