Hay más ejemplos de AWS SDK disponibles en el repositorio de GitHub de ejemplos de AWS SDK de documentos
Ejemplos de Centro de socios con SDK para Python (Boto3)
Los siguientes ejemplos de código muestran cómo realizar acciones e implementar escenarios comunes usando AWS SDK para Python (Boto3) con Centro de socios.
Las acciones son extractos de código de programas más grandes y deben ejecutarse en contexto. Mientras las acciones muestran cómo llamar a las distintas funciones de servicio, es posible ver las acciones en contexto en los escenarios relacionados.
Los escenarios son ejemplos de código que muestran cómo llevar a cabo una tarea específica a través de llamadas a varias funciones dentro del servicio o combinado con otros Servicios de AWS.
En cada ejemplo se incluye un enlace al código de origen completo, con instrucciones de configuración y ejecución del código en el contexto.
Temas
Acciones
En el siguiente ejemplo de código, se muestra cómo utilizar AssignOpportunity.
- SDK para Python (Boto3)
-
Reasignar una oportunidad existente a otro usuario.
#!/usr/bin/env python """ Purpose PC-API-07 Assigning a new owner """ import logging import boto3 import utils.helpers as helper from botocore.client import ClientError from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def assign_opportunity(identifier): assign_opportunity_request ={ "Catalog": CATALOG_TO_USE, "Identifier": identifier, "Assignee": { "BusinessTitle": "OpportunityOwner", "Email": "test@test.com", "FirstName": "John", "LastName": "Doe" } } try: # Perform an API call response = partner_central_client.assign_opportunity(**assign_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): identifier = "O4236468" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Assigning a new owner to an opportunity.") print("-" * 88) helper.pretty_print_datetime(assign_opportunity(identifier)) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte AssignOpportunity en la Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar AssociateOpportunity.
- SDK para Python (Boto3)
-
Crear una asociación formal entre una oportunidad y varias entidades relacionadas.
#!/usr/bin/env python """ Purpose PC-API -11 Associating a product PC-API -12 Associating a solution PC-API -13 Associating an offer """ import logging import boto3 import utils.helpers as helper from botocore.client import ClientError from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def associate_opportunity(entity_type, entity_identifier, opportunityIdentifier): associate_opportunity_request ={ "Catalog": CATALOG_TO_USE, "OpportunityIdentifier" : opportunityIdentifier, "RelatedEntityType" : entity_type, "RelatedEntityIdentifier" : entity_identifier } try: # Perform an API call response = partner_central_client.associate_opportunity(**associate_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): #entity_type = Solutions | AWSProducts | AWSMarketplaceOffers entity_type = "Solutions" entity_identifier = "S-0059717" opportunityIdentifier = "O5465588" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Associate Opportunity.") print("-" * 88) helper.pretty_print_datetime(associate_opportunity(entity_type, entity_identifier, opportunityIdentifier)) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte AssociateOpportunity en la Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar CreateOpportunity.
- SDK para Python (Boto3)
-
Crear una oportunidad.
#!/usr/bin/env python import boto3 import logging import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import utils.helpers as helper import utils.stringify_details as sd from botocore.client import ClientError from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" def create_opportunity(partner_central_client): create_opportunity_request = helper.remove_nulls(sd.stringify_json("src/create_opportunity/createOpportunity.json")) try: # Perform an API call response = partner_central_client.create_opportunity(**create_opportunity_request) helper.pretty_print_datetime(response) # Retrieve the opportunity details get_response = partner_central_client.get_opportunity( Identifier=response["Id"], Catalog=CATALOG_TO_USE ) helper.pretty_print_datetime(get_response) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Create Opportunity.") print("-" * 88) partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) create_opportunity(partner_central_client) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte CreateOpportunity en la Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar DisassociateOpportunity.
- SDK para Python (Boto3)
-
Eliminar una asociación existente entre una oportunidad y entidades relacionadas.
#!/usr/bin/env python """ Purpose PC-API -14 Removing a Solution PC-API -15 Removing an offer PC-API -16 Removing a product """ import logging import boto3 import utils.helpers as helper from botocore.client import ClientError from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def disassociate_opportunity(entity_type, entity_identifier, opportunityIdentifier): disassociate_opportunity_request ={ "Catalog": CATALOG_TO_USE, "OpportunityIdentifier" : opportunityIdentifier, "RelatedEntityType" : entity_type, "RelatedEntityIdentifier" : entity_identifier } try: # Perform an API call response = partner_central_client.disassociate_opportunity(**disassociate_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): #entity_type = Solutions | AWSProducts | AWSMarketplaceOffers entity_type = "Solutions" entity_identifier = "S-0049999" opportunityIdentifier = "O4397574" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Get updated Opportunity.") print("-" * 88) helper.pretty_print_datetime(disassociate_opportunity(entity_type, entity_identifier, opportunityIdentifier)) if __name__ == "__main__": usage_demo()-
Para obtener información sobre las API, consulte DisassociateOpportunity en la Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar GetAwsOpportunitySummary.
- SDK para Python (Boto3)
-
Recuperar un resumen de una oportunidad de AWS.
#!/usr/bin/env python """ Purpose PC-API-25 Retrieves a summary of an AWS Opportunity. LifeCycle.ReviewStatus=Approved """ import logging import boto3 import utils.helpers as helper from botocore.client import ClientError from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def get_opportunity(identifier): get_opportunity_request ={ "Catalog": CATALOG_TO_USE, "RelatedOpportunityIdentifier": identifier } try: # Perform an API call response = partner_central_client.get_aws_opportunity_summary(**get_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): identifier = "O5465588" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Get AWS Opportunity summary.") print("-" * 88) helper.pretty_print_datetime(get_opportunity(identifier)) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte GetAwsOpportunitySummary en la Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar GetEngagementInvitation.
- SDK para Python (Boto3)
-
Recupera los detalles de una invitación de participación compartida por AWS con un socio.
#!/usr/bin/env python """ Purpose PC-API-22 GetOpportunityEngagementInvitation - Retrieves details of a specific engagement invitation. This operation allows partners to view the invitation and its associated information, such as the customer, project, and lifecycle details. """ import json import logging import boto3 import utils.helpers as helper from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def get_opportunity_engagement_invitation(identifier): get_opportunity_engagement_invitation_request ={ "Catalog": CATALOG_TO_USE, "Identifier": identifier } try: # Perform an API call response = partner_central_client.get_engagement_invitation(**get_opportunity_engagement_invitation_request) return response except Exception as err: # Catch all client exceptions print(json.dumps(err.response)) def usage_demo(): identifier = "arn:aws:partnercentral-selling:us-east-1:aws:catalog/Sandbox/engagement-invitation/engi-0000000IS0Qga" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Given the ARN identifier, retrieve details of Opportunity Engagement Invitation.") print("-" * 88) helper.pretty_print_datetime(get_opportunity_engagement_invitation(identifier)) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte GetEngagementInvitation en la Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar GetOpportunity.
- SDK para Python (Boto3)
-
Obtener una oportunidad.
#!/usr/bin/env python """ Purpose PC-API -08 Get updated Opportunity given opportunity id """ import logging import boto3 import utils.helpers as helper from botocore.client import ClientError from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def get_opportunity(identifier): get_opportunity_request ={ "Catalog": CATALOG_TO_USE, "Identifier": identifier } try: # Perform an API call response = partner_central_client.get_opportunity(**get_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): identifier = "O5465588" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Get updated Opportunity.") print("-" * 88) helper.pretty_print_datetime(get_opportunity(identifier)) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte GetOpportunity en Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar ListEngagementInvitations.
- SDK para Python (Boto3)
-
Recupera una lista de las invitaciones de participación enviadas al socio.
#!/usr/bin/env python """ Purpose PC-API-21 ListEngagementInvitations - Retrieves a list of engagement invitations based on specified criteria. This operation allows partners to view all invitations to engagement. """ import json import logging import boto3 import utils.helpers as helper from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def list_engagement_invitations(): list_engagement_invitations_request ={ "Catalog": CATALOG_TO_USE, "MaxResults": 20 } try: # Perform an API call response = partner_central_client.list_engagement_invitations(**list_engagement_invitations_request) return response except Exception as err: # Catch all client exceptions print(json.dumps(err.response)) def usage_demo(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Retrieve list of Engagement Invitations.") print("-" * 88) helper.pretty_print_datetime(list_engagement_invitations()) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte ListEngagementInvitations en la Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar ListOpportunities.
- SDK para Python (Boto3)
-
Mostrar las oportunidades.
#!/usr/bin/env python """ Purpose PC-API -18 Getting list of Opportunities """ import json import logging import boto3 import utils.helpers as helper from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def get_list_of_opportunities(): opportunity_list = [] list_opportunities_request ={ "Catalog": CATALOG_TO_USE, "MaxResults": 20 } try: # Perform an API call response = partner_central_client.list_opportunities(**list_opportunities_request) opportunity_list.extend(response["OpportunitySummaries"]) while "NextToken" in response and response["NextToken"] is not None: list_opportunities_request["NextToken"] = response["NextToken"] response = partner_central_client.list_opportunities(**list_opportunities_request) opportunity_list.extend(response["OpportunitySummaries"]) return opportunity_list except Exception as err: # Catch all client exceptions print(json.dumps(err.response)) def usage_demo(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Getting list of Opportunities.") print("-" * 88) helper.pretty_print_datetime(get_list_of_opportunities()) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte ListOpportunities en la Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar ListSolutions.
- SDK para Python (Boto3)
-
Recupera una lista de las soluciones para socios que el socio registró en Centro de socios.
#!/usr/bin/env python """ Purpose PC-API-10 Getting list of solutions """ import logging import boto3 import utils.helpers as helper from botocore.client import ClientError from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def get_list_of_solutions(): list_solutions_request ={ "Catalog": CATALOG_TO_USE, "MaxResults": 20 } try: # Perform an API call response = partner_central_client.list_solutions(**list_solutions_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Getting list of solutions.") print("-" * 88) helper.pretty_print_datetime(get_list_of_solutions()) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte ListSolutions en la Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar RejectEngagementInvitation.
- SDK para Python (Boto3)
-
Rechaza una EngagementInvitation compartida por AWS.
#!/usr/bin/env python """ Purpose PC-API-05 AWS Originated AO rejection - RejectOpportunityEngagementInvitation - Rejects a engagement invitation. This action indicates that the partner does not wish to participate in the engagement and provides a reason for the rejection. Upon rejection, a OpportunityEngagementInvitationRejected event is triggered. Subsequently, the invitation will no longer be available for the partner to act on. """ import json import logging import boto3 import utils.helpers as helper from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def reject_opportunity_engagement_invitation(identifier, reject_reason): reject_opportunity_engagement_invitation_request ={ "Catalog": CATALOG_TO_USE, "Identifier": identifier, "RejectionReason": reject_reason } try: # Perform an API call response = partner_central_client.reject_engagement_invitation(**reject_opportunity_engagement_invitation_request) return response except Exception as err: # Catch all client exceptions print(json.dumps(err.response)) def usage_demo(): identifier = "arn:aws:partnercentral:us-east-1::catalog/Sandbox/engagement-invitation/engi-0000002isviga" reject_reason = "Customer problem unclear" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Given the ARN identifier and reject reason, reject the Opportunity Engagement Invitation.") print("-" * 88) helper.pretty_print_datetime(reject_opportunity_engagement_invitation(identifier, reject_reason)) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte RejectEngagementInvitation en la Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar StartEngagementByAcceptingInvitationTask.
- SDK para Python (Boto3)
-
Inicia la participación aceptando una EngagementInvitation.
#!/usr/bin/env python """ Purpose PC-API -11 Associating a product PC-API -12 Associating a solution PC-API -13 Associating an offer """ import logging import boto3 import utils.helpers as helper from botocore.client import ClientError from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def get_opportunity(identifier): get_opportunity_request ={ "Identifier": identifier, "Catalog": CATALOG_TO_USE } try: # Perform an API call response = partner_central_client.get_engagement_invitation(**get_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def start_engagement_by_accepting_invitation_task(identifier): response = get_opportunity(identifier) if ( response['Status'] == 'PENDING') : accept_opportunity_engagement_invitation_request ={ "Catalog": CATALOG_TO_USE, "Identifier" : identifier, "ClientToken": "test-123456" } try: # Perform an API call response = partner_central_client.start_engagement_by_accepting_invitation_task(**accept_opportunity_engagement_invitation_request) return response except ClientError as err: # Catch all client exceptions print(err.response) return None else: return None def usage_demo(): identifier = "arn:aws:partnercentral:us-east-1::catalog/Sandbox/engagement-invitation/engi-0000002isusga" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Get updated Opportunity.") print("-" * 88) helper.pretty_print_datetime(start_engagement_by_accepting_invitation_task(identifier)) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte StartEngagementByAcceptingInvitationTask en la Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar StartEngagementFromOpportunityTask.
- SDK para Python (Boto3)
-
Inicia el proceso de participación a partir de una oportunidad existente al aceptar la invitación de participación y crear la oportunidad correspondiente en el sistema del socio.
#!/usr/bin/env python """ Purpose PC-API -11 Associating a product PC-API -12 Associating a solution PC-API -13 Associating an offer """ import logging import boto3 import utils.helpers as helper from botocore.client import ClientError from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def start_engagement_from_opportunity_task(identifier): start_engagement_from_opportunity_task_request ={ "AwsSubmission": { "InvolvementType": "Co-Sell", "Visibility": "Full" }, "Catalog": CATALOG_TO_USE, "Identifier" : identifier, "ClientToken": "test-annjqwesdsd99" } try: # Perform an API call response = partner_central_client.start_engagement_from_opportunity_task(**start_engagement_from_opportunity_task_request) return response except ClientError as err: # Catch all client exceptions print(err.response) return None def usage_demo(): identifier = "O5465588" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Start Engagement from Opportunity Task.") print("-" * 88) helper.pretty_print_datetime(start_engagement_from_opportunity_task(identifier)) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte StartEngagementFromOpportunityTask en la Referencia de la API de AWS SDK para Python (Boto3).
-
En el siguiente ejemplo de código, se muestra cómo utilizar UpdateOpportunity.
- SDK para Python (Boto3)
-
Actualizar una oportunidad.
#!/usr/bin/env python """ Purpose PC-API-2 Updating Partner Originated Opportunity """ import logging import boto3 import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import utils.helpers as helper from botocore.client import ClientError import utils.stringify_details as sd from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def get_opportunity(identifier): get_opportunity_request ={ "Identifier": identifier, "Catalog": CATALOG_TO_USE } try: # Perform an API call response = partner_central_client.get_opportunity(**get_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def update_opportunity(): update_opportunity_request_orig = sd.stringify_json("src/update_opportunity/update_opportunity_technical_validation.json") update_opportunity_request = helper.remove_nulls(update_opportunity_request_orig) try: # Perform an API call response = partner_central_client.update_opportunity(**update_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def update_opportunity_if_eligible(identifier): response = get_opportunity(identifier) if response is not None: return update_opportunity() else: print("Failed to retrieve opportunity details") def usage_demo(): identifier = "O5465588" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Updating opportunity.") print("-" * 88) helper.pretty_print_datetime(update_opportunity_if_eligible(identifier)) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte UpdateOpportunity en la Referencia de la API de AWS SDK para Python (Boto3).
-
Escenarios
En el siguiente ejemplo de código, se muestra cómo:
Desvincular una entidad antigua.
Asociar una entidad nueva.
- SDK para Python (Boto3)
-
nota
Hay más en GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS
. Actualizar la entidad asociada a una oportunidad
#!/usr/bin/env python """ Purpose PC-API -17 Replacing a solution """ import logging import boto3 import utils.helpers as helper from botocore.client import ClientError from utils.constants import CATALOG_TO_USE serviceName = "partnercentral-selling" partner_central_client = boto3.client( service_name=serviceName, region_name='us-east-1' ) def replace_solution(original_entity_identifier, new_entity_identifier, opportunityIdentifier): disassociate_opportunity_request ={ "Catalog": CATALOG_TO_USE, "OpportunityIdentifier" : opportunityIdentifier, "RelatedEntityType" : "Solutions", "RelatedEntityIdentifier" : original_entity_identifier } associate_opportunity_request ={ "Catalog": CATALOG_TO_USE, "OpportunityIdentifier" : opportunityIdentifier, "RelatedEntityType" : "Solutions", "RelatedEntityIdentifier" : new_entity_identifier } try: # Perform an API call response = partner_central_client.disassociate_opportunity(**disassociate_opportunity_request) response = partner_central_client.associate_opportunity(**associate_opportunity_request) return response except ClientError as err: # Catch all client exceptions print(err.response) def usage_demo(): original_entity_identifier = "S-0049999" new_entity_identifier = "S-0050014" opportunityIdentifier = "O4397574" logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") print("-" * 88) print("Replacing a solution.") print("-" * 88) helper.pretty_print_datetime(replace_solution(original_entity_identifier, new_entity_identifier, opportunityIdentifier)) if __name__ == "__main__": usage_demo()-
Para obtener información sobre la API, consulte los siguientes temas en la Referencia de la API de AWS SDK para Python (Boto3).
-