使用以下方式描述公开发售 AWS SDK - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用以下方式描述公开发售 AWS SDK

以下代码示例展示了如何描述公开发行。

Java
SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整的示例,学习如何在AWS Marketplace API参考代码库存储库中设置和运行。

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 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; } }
  • 有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 DescribeEntity” 中的。

Python
SDK适用于 Python (Boto3)
注意

还有更多相关信息 GitHub。查找完整的示例,学习如何在AWS Marketplace API参考代码库存储库中设置和运行。

# 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()
  • 有关API详细信息,请参阅DescribeEntity中的 AWS SDKPython (Boto3) API 参考。