def associate_product()

in service-catalog-and-license-manager-entitlement/handler.py [0:0]


def associate_product(event):

    """
    Purpose: extract product product_id then associate with Marketplace portfolio.
    """

    client = boto3.client('servicecatalog')
    message = event['detail']['responseElements']
    product_id = message['productViewDetail']['productViewSummary']['productId']
    try:
        response = client.associate_product_with_portfolio(
                        ProductId=product_id,
                        PortfolioId=portfolio_id)
        logging.info('%s is associated with Portfolio %s', product_id, portfolio_id)
        return response
    except ClientError as e:
        if e.response['Error']['Code'] == 'ResourceNotFoundException':
            logging.error(e)
        else:
            raise e