Get the status of an agreement using an AWS SDK - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Get the status of an agreement using an AWS SDK

The following code examples show how to get the status of an agreement.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Marketplace API Reference Code Library repository.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 package com.example.awsmarketplace.agreementapi; import static com.example.awsmarketplace.utils.ReferenceCodesConstants.AGREEMENT_ID; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.http.apache.ApacheHttpClient; import software.amazon.awssdk.services.marketplaceagreement.MarketplaceAgreementClient; import software.amazon.awssdk.services.marketplaceagreement.model.DescribeAgreementRequest; import software.amazon.awssdk.services.marketplaceagreement.model.DescribeAgreementResponse; public class GetAgreementStatus { public static void main(String[] args) { String agreementId = args.length > 0 ? args[0] : AGREEMENT_ID; DescribeAgreementResponse describeAgreementResponse = getDescribeAgreementResponse(agreementId); System.out.println("Agreement status is " + describeAgreementResponse.status()); } public static DescribeAgreementResponse getDescribeAgreementResponse(String agreementId) { MarketplaceAgreementClient marketplaceAgreementClient = MarketplaceAgreementClient.builder() .httpClient(ApacheHttpClient.builder().build()) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); DescribeAgreementRequest describeAgreementRequest = DescribeAgreementRequest.builder() .agreementId(agreementId) .build(); DescribeAgreementResponse describeAgreementResponse = marketplaceAgreementClient.describeAgreement(describeAgreementRequest); return describeAgreementResponse; } }
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Marketplace API Reference Code Library repository.

# 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) to get all agreement status AG-13 Example Usage: python3 get_agreement_status.py --agreement-id <agreement-id> """ import argparse import logging import boto3 from botocore.exceptions import ClientError mp_client = boto3.client("marketplace-agreement") logger = logging.getLogger(__name__) def get_agreement(agreement_id): try: response = mp_client.describe_agreement(agreementId=agreement_id) return response except ClientError as e: logger.error(f"Could not complete search_agreements request. {e}") return None if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( "--agreement-id", "-aid", help="Provide agreement ID to describe agreement status", required=True, ) args = parser.parse_args() response = get_agreement(agreement_id=args.agreement_id) if response is not None: print(f"Agreement status: {response['status']}") else: print(f"No agreement found for {args.agreement_id}")
  • For API details, see DescribeAgreement in AWS SDK for Python (Boto3) API Reference.