Elenco delle politiche del progetto (SDK) - Rekognition

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à.

Elenco delle politiche del progetto (SDK)

Puoi utilizzare l'ListProjectPoliciesoperazione per elencare le politiche di progetto allegate a un progetto Amazon Rekognition Custom Labels.

Per elencare le policy di progetto collegate a un progetto (SDK)
  1. Se non l'hai ancora fatto, installa e configura l'SDKAWS CLI e gliAWS SDK. Per ulteriori informazioni, consulta Passaggio 4: configura il AWS CLI e AWS SDKs.

  2. Usa il codice seguente per elencare le politiche del progetto.

    AWS CLI

    Passaproject-arn al nome della risorsa Amazon del progetto per il quale desideri elencare le politiche del progetto allegate.

    aws rekognition list-project-policies \ --project-arn project-arn \ --profile custom-labels-access
    Python

    Eseguire il il il il il il il il il Fornisci i seguenti parametri della riga di comando:

    • project_arn — il nome della risorsa Amazon del progetto per il quale desideri elencare le politiche del progetto allegate.

    Ad esempio: python list_project_policies.py project_arn

    # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Purpose Amazon Rekognition Custom Labels model example used in the service documentation: https://docs.aws.amazon.com/rekognition/latest/customlabels-dg/md-copy-model-sdk.html Shows how to list the project policies in an Amazon Rekogntion Custom Labels project. """ import argparse import logging import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) def display_project_policy(project_policy): """ Displays information about a Custom Labels project policy. :param project_policy: The project policy (ProjectPolicy) that you want to display information about. """ print(f"Policy name: {(project_policy['PolicyName'])}") print(f"Project Arn: {project_policy['ProjectArn']}") print(f"Document: {(project_policy['PolicyDocument'])}") print(f"Revision ID: {(project_policy['PolicyRevisionId'])}") print() def list_project_policies(rek_client, project_arn): """ Describes an Amazon Rekognition Custom Labels project, or all projects. :param rek_client: The Amazon Rekognition Custom Labels Boto3 client. :param project_arn: The Amazon Resource Name of the project you want to use. """ try: max_results = 5 pagination_token = '' finished = False logger.info("Listing project policies in: %s.", project_arn) print('Projects\n--------') while not finished: response = rek_client.list_project_policies( ProjectArn=project_arn, MaxResults=max_results, NextToken=pagination_token) for project in response['ProjectPolicies']: display_project_policy(project) if 'NextToken' in response: pagination_token = response['NextToken'] else: finished = True logger.info("Finished listing project policies.") except ClientError as err: logger.exception( "Couldn't list policies for - %s: %s", project_arn,err.response['Error']['Message']) raise def add_arguments(parser): """ Adds command line arguments to the parser. :param parser: The command line parser. """ parser.add_argument( "project_arn", help="The Amazon Resource Name of the project for which you want to list project policies." ) def main(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") try: # get command line arguments parser = argparse.ArgumentParser(usage=argparse.SUPPRESS) add_arguments(parser) args = parser.parse_args() print(f"Listing project policies in: {args.project_arn}") # List the project policies. session = boto3.Session(profile_name='custom-labels-access') rekognition_client = session.client("rekognition") list_project_policies(rekognition_client, args.project_arn) except ClientError as err: print(f"Problem list project_policies: {err}") if __name__ == "__main__": main()
    Java V2

    Eseguire il il il il il il il il il Fornisci i seguenti parametri della riga di comando:

    • project_arn — L'ARN del progetto che contiene le politiche di progetto che desideri elencare.

    /* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ package com.example.rekognition; import java.util.logging.Level; import java.util.logging.Logger; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rekognition.RekognitionClient; import software.amazon.awssdk.services.rekognition.model.ListProjectPoliciesRequest; import software.amazon.awssdk.services.rekognition.model.ListProjectPoliciesResponse; import software.amazon.awssdk.services.rekognition.model.ProjectPolicy; import software.amazon.awssdk.services.rekognition.model.RekognitionException; public class ListProjectPolicies { public static final Logger logger = Logger.getLogger(ListProjectPolicies.class.getName()); public static void listMyProjectPolicies(RekognitionClient rekClient, String projectArn) { try { logger.log(Level.INFO, "Listing project policies for project: {0}", projectArn); // List the project policies. Boolean finished = false; String nextToken = null; while (Boolean.FALSE.equals(finished)) { ListProjectPoliciesRequest listProjectPoliciesRequest = ListProjectPoliciesRequest.builder() .maxResults(5) .projectArn(projectArn) .nextToken(nextToken) .build(); ListProjectPoliciesResponse response = rekClient.listProjectPolicies(listProjectPoliciesRequest); for (ProjectPolicy projectPolicy : response.projectPolicies()) { System.out.println(String.format("Name: %s", projectPolicy.policyName())); System.out.println(String.format("Revision ID: %s\n", projectPolicy.policyRevisionId())); } nextToken = response.nextToken(); if (nextToken == null) { finished = true; } } logger.log(Level.INFO, "Finished listing project policies for project: {0}", projectArn); } catch ( RekognitionException e) { logger.log(Level.SEVERE, "Client error occurred: {0}", e.getMessage()); throw e; } } public static void main(String args[]) { final String USAGE = "\n" + "Usage: " + "<project_arn> \n\n" + "Where:\n" + " project_arn - The ARN of the project with the project policies that you want to list.\n\n"; ; if (args.length != 1) { System.out.println(USAGE); System.exit(1); } String projectArn = args[0]; try { RekognitionClient rekClient = RekognitionClient.builder() .credentialsProvider(ProfileCredentialsProvider.create("custom-labels-access")) .region(Region.US_WEST_2) .build(); // List the project policies. listMyProjectPolicies(rekClient, projectArn); rekClient.close(); } catch (RekognitionException rekError) { logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage()); System.exit(1); } } }