L'API Reference di AWS Marketplace è stato ristrutturato. Per ulteriori informazioni sulle operazioni API supportate, consulta l'AWS Marketplace API Reference.
Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Descrivi un'offerta pubblica utilizzando un AWS SDK
Gli esempi di codice seguenti mostrano come descrivere un’offerta pubblica.
- Java
-
- SDK per 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
-
- SDK per 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()
Per un elenco completo delle guide per sviluppatori AWS SDK e degli esempi di codice, consulta. L'utilizzo di questo servizio con un AWS SDK Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell’SDK.