La référence de l'API AWS Marketplace a été restructurée. Pour plus d'informations sur les opérations d'API prises en charge, consultez le manuel AWS Marketplace API Reference.
Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
Décrivez une offre publique à l'aide d'un AWS Kit SDK
Les exemples de code suivants montrent comment décrire une offre publique.
- Java
-
- SDK pour Java 2.x
-
package com.example.awsmarketplace.catalogapi;
import static com.example.awsmarketplace.utils.ReferenceCodesConstants.*;
import com.example.awsmarketplace.utils.ReferenceCodesUtils;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.http.apache.ApacheHttpClient;
import software.amazon.awssdk.services.marketplacecatalog.MarketplaceCatalogClient;
import software.amazon.awssdk.services.marketplacecatalog.model.DescribeEntityRequest;
import software.amazon.awssdk.services.marketplacecatalog.model.DescribeEntityResponse;
public class DescribeEntity {
/*
* Describe my AMI or SaaS or Container product and check if it contains all the information I need to know about the product
*/
public static void main(String[] args) {
String offerId = args.length > 0 ? args[0] : OFFER_ID;
DescribeEntityResponse describeEntityResponse = getDescribeEntityResponse(offerId);
ReferenceCodesUtils.formatOutput(describeEntityResponse);
}
public static DescribeEntityResponse getDescribeEntityResponse(String offerId) {
MarketplaceCatalogClient marketplaceCatalogClient =
MarketplaceCatalogClient.builder()
.httpClient(ApacheHttpClient.builder().build())
.credentialsProvider(ProfileCredentialsProvider.create())
.build();
DescribeEntityRequest describeEntityRequest =
DescribeEntityRequest.builder()
.catalog(AWS_MP_CATALOG)
.entityId(offerId)
.build();
DescribeEntityResponse describeEntityResponse = marketplaceCatalogClient.describeEntity(describeEntityRequest);
return describeEntityResponse;
}
}
- Python
-
- Kit SDK for Python (Boto3)
-
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Purpose
Shows how to use the AWS SDK for Python (Boto3) search for offer information in the AWS Marketplace Catalog
CAPI-29
"""
import json
import logging
import boto3
from botocore.exceptions import ClientError
logger = logging.getLogger(__name__)
OFFER_ID = "offer-1111111111111"
def pretty_print(response):
json_object = json.dumps(response, indent=4)
print(json_object)
def get_offer_information(mp_client, entity_id):
"""
Returns information about a given offer
Args: entity_id str: Entity to return
Returns: dict: Dictionary of offer information
"""
try:
response = mp_client.describe_entity(
Catalog="AWSMarketplace",
EntityId=entity_id,
)
return response
except ClientError as e:
if e.response["Error"]["Code"] == "ResourceNotFoundException":
logger.error("Offer with ID %s not found.", entity_id)
else:
logger.error("Unexpected error: %s", e)
def usage_demo():
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
print("-" * 88)
print("Looking for an offer in the AWS Marketplace Catalog.")
print("-" * 88)
mp_client = boto3.client("marketplace-catalog")
pretty_print(get_offer_information(mp_client, OFFER_ID))
if __name__ == "__main__":
usage_demo()
Pour obtenir la liste complète des guides du développeur du AWS SDK et des exemples de code, consultezL'utilisation de ce service avec AWS Kit SDK. Cette rubrique comprend également des informations sur le démarrage et sur les versions précédentes du kit SDK.