View a markdown version of this page

Usare StartCrawler con un AWS SDK o CLI - AWS Aderenza

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

Usare StartCrawler con un AWS SDK o CLI

I seguenti esempi di codice mostrano come usare StartCrawler.

Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:

.NET
SDK per .NET
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

/// <summary> /// Start an AWS Glue crawler. /// </summary> /// <param name="crawlerName">The name of the crawler.</param> /// <returns>A Boolean value indicating the success of the action.</returns> public async Task<bool> StartCrawlerAsync(string crawlerName) { var crawlerRequest = new StartCrawlerRequest { Name = crawlerName, }; var response = await _amazonGlue.StartCrawlerAsync(crawlerRequest); return response.HttpStatusCode == System.Net.HttpStatusCode.OK; }
  • Per i dettagli sull'API, consulta StartCrawler nel AWS SDK per .NET Riferimento API.

C++
SDK per C++
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region in which the bucket was created (overrides config file). // clientConfig.region = "us-east-1"; Aws::Glue::GlueClient client(clientConfig); Aws::Glue::Model::StartCrawlerRequest request; request.SetName(CRAWLER_NAME); Aws::Glue::Model::StartCrawlerOutcome outcome = client.StartCrawler(request); if (outcome.IsSuccess() || (Aws::Glue::GlueErrors::CRAWLER_RUNNING == outcome.GetError().GetErrorType())) { if (!outcome.IsSuccess()) { std::cout << "Crawler was already started." << std::endl; } else { std::cout << "Successfully started crawler." << std::endl; } std::cout << "This may take a while to run." << std::endl; Aws::Glue::Model::CrawlerState crawlerState = Aws::Glue::Model::CrawlerState::NOT_SET; int iterations = 0; while (Aws::Glue::Model::CrawlerState::READY != crawlerState) { std::this_thread::sleep_for(std::chrono::seconds(1)); ++iterations; if ((iterations % 10) == 0) { // Log status every 10 seconds. std::cout << "Crawler status " << Aws::Glue::Model::CrawlerStateMapper::GetNameForCrawlerState( crawlerState) << ". After " << iterations << " seconds elapsed." << std::endl; } Aws::Glue::Model::GetCrawlerRequest getCrawlerRequest; getCrawlerRequest.SetName(CRAWLER_NAME); Aws::Glue::Model::GetCrawlerOutcome getCrawlerOutcome = client.GetCrawler( getCrawlerRequest); if (getCrawlerOutcome.IsSuccess()) { crawlerState = getCrawlerOutcome.GetResult().GetCrawler().GetState(); } else { std::cerr << "Error getting crawler. " << getCrawlerOutcome.GetError().GetMessage() << std::endl; break; } } if (Aws::Glue::Model::CrawlerState::READY == crawlerState) { std::cout << "Crawler finished running after " << iterations << " seconds." << std::endl; } } else { std::cerr << "Error starting a crawler. " << outcome.GetError().GetMessage() << std::endl; deleteAssets(CRAWLER_NAME, CRAWLER_DATABASE_NAME, "", bucketName, clientConfig); return false; }
  • Per i dettagli sull'API, consulta StartCrawler nel AWS SDK per C++ Riferimento API.

CLI
AWS CLI

Come avviare un crawler

L’esempio start-crawler seguente avvia un crawler.

aws glue start-crawler \ --name my-crawler

Questo comando non produce output.

Per ulteriori informazioni, consulta Definizione di crawler nella Guida per gli sviluppatori di AWS Glue.

  • Per i dettagli sull'API, consulta StartCrawler nel AWS CLI Riferimento al comando.

Java
SDK per Java 2.x
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

/** * Starts a specific AWS Glue crawler. * * @param glueClient the AWS Glue client to use for the crawler operation * @param crawlerName the name of the crawler to start * @throws GlueException if there is an error starting the crawler */ public static void startSpecificCrawler(GlueClient glueClient, String crawlerName) { try { StartCrawlerRequest crawlerRequest = StartCrawlerRequest.builder() .name(crawlerName) .build(); glueClient.startCrawler(crawlerRequest); System.out.println(crawlerName + " was successfully started!"); } catch (GlueException e) { throw e; } }
  • Per i dettagli sull'API, consulta StartCrawler nel AWS SDK for Java 2.x Riferimento API.

JavaScript
SDK per JavaScript (v3)
Nota

C'è dell'altro GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

const startCrawler = (name) => { const client = new GlueClient({}); const command = new StartCrawlerCommand({ Name: name, }); return client.send(command); };
  • Per i dettagli sull'API, consulta StartCrawler nel AWS SDK per JavaScript Riferimento API.

Kotlin
SDK per Kotlin
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

suspend fun startSpecificCrawler(crawlerName: String?) { val request = StartCrawlerRequest { name = crawlerName } GlueClient.fromEnvironment { region = "us-west-2" }.use { glueClient -> glueClient.startCrawler(request) println("$crawlerName was successfully started.") } }
  • Per i dettagli sull'API, consulta StartCrawler nel AWS Riferimento all'API SDK per Kotlin.

PHP
SDK per PHP
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

$crawlerName = "example-crawler-test-" . $uniqid; $databaseName = "doc-example-database-$uniqid"; $glueService->startCrawler($crawlerName); public function startCrawler($crawlerName): Result { return $this->glueClient->startCrawler([ 'Name' => $crawlerName, ]); }
  • Per i dettagli sull'API, consulta StartCrawler nel AWS SDK per PHP Riferimento API.

Python
SDK per Python (Boto3)
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

class GlueWrapper: """Encapsulates AWS Glue actions.""" def __init__(self, glue_client): """ :param glue_client: A Boto3 Glue client. """ self.glue_client = glue_client def start_crawler(self, name): """ Starts a crawler. The crawler crawls its configured target and creates metadata that describes the data it finds in the target data source. :param name: The name of the crawler to start. """ try: self.glue_client.start_crawler(Name=name) except ClientError as err: logger.error( "Couldn't start crawler %s. Here's why: %s: %s", name, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
  • Per i dettagli sull'API, consulta StartCrawler nel AWS Riferimento alle API SDK per Python (Boto3).

Ruby
SDK per Ruby
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

# The `GlueWrapper` class serves as a wrapper around the AWS Glue API, providing a simplified interface for common operations. # It encapsulates the functionality of the AWS SDK for Glue and provides methods for interacting with Glue crawlers, databases, tables, jobs, and S3 resources. # The class initializes with a Glue client and a logger, allowing it to make API calls and log any errors or informational messages. class GlueWrapper def initialize(glue_client, logger) @glue_client = glue_client @logger = logger end # Starts a crawler with the specified name. # # @param name [String] The name of the crawler to start. # @return [void] def start_crawler(name) @glue_client.start_crawler(name: name) rescue Aws::Glue::Errors::ServiceError => e @logger.error("Glue could not start crawler #{name}: \n#{e.message}") raise end
  • Per i dettagli sull'API, consulta StartCrawler nel AWS SDK per Ruby Riferimento API.

Rust
SDK per Rust
Nota

C'è altro su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

let start_crawler = glue.start_crawler().name(self.crawler()).send().await; match start_crawler { Ok(_) => Ok(()), Err(err) => { let glue_err: aws_sdk_glue::Error = err.into(); match glue_err { aws_sdk_glue::Error::CrawlerRunningException(_) => Ok(()), _ => Err(GlueMvpError::GlueSdk(glue_err)), } } }?;
  • Per i dettagli sull'API, consulta StartCrawler nel AWS SDK per Rust API di riferimento.

SAP ABAP
SDK per SAP ABAP
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

TRY. " iv_crawler_name = 'my-crawler' lo_glu->startcrawler( iv_name = iv_crawler_name ). MESSAGE 'Crawler started successfully.' TYPE 'I'. CATCH /aws1/cx_glucrawlerrunningex. MESSAGE 'Crawler is already running.' TYPE 'I'. CATCH /aws1/cx_gluentitynotfoundex. MESSAGE 'Crawler does not exist.' TYPE 'E'. CATCH /aws1/cx_gluoperationtimeoutex INTO DATA(lo_timeout_ex). DATA(lv_timeout_error) = lo_timeout_ex->if_message~get_longtext( ). MESSAGE lv_timeout_error TYPE 'E'. ENDTRY.
  • Per i dettagli sull'API, consulta StartCrawler nel AWS Riferimento all'API SDK per SAP ABAP.

Swift
SDK per Swift
Nota

C'è altro su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

import AWSClientRuntime import AWSGlue /// Start running an AWS Glue crawler. /// /// - Parameters: /// - glueClient: The AWS Glue client to use when starting the crawler. /// - name: The name of the crawler to start running. /// /// - Returns: `true` if the crawler is started successfully, otherwise `false`. func startCrawler(glueClient: GlueClient, name: String) async -> Bool { do { _ = try await glueClient.startCrawler( input: StartCrawlerInput(name: name) ) } catch { print("*** An unexpected error occurred starting the crawler.") return false } return true }
  • Per i dettagli sull'API, consulta StartCrawler nel AWS Riferimento SDK per Swift API.

Per un elenco completo di AWS Guide per sviluppatori SDK ed esempi di codice, consulta L'utilizzo di questo servizio con un AWS SDK. Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell’SDK.