- AWS Code Sample

This version of the AWS Code Sample Catalog has been replaced by the AWS Code Library, which contains new and updated code examples. demonstrates how to get an AWS Glue crawler.


To run this Java (SDK V2) code example, ensure that you have set up your development environment, including your credentials. For more information, see AWS SDK for Java 2.x Developer Guide.

/* Copyright, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ package com.example.glue; import; import; import; import; import; import; import java.time.Instant; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.Locale; /** * Before running this Java V2 code example, set up your development environment, including your credentials. * * For more information, see the following documentation topic: * * */ public class GetCrawler { public static void main(String[] args) { final String usage = "\n" + "Usage:\n" + " <crawlerName>\n\n" + "Where:\n" + " crawlerName - The name of the crawler. \n" ; if (args.length != 1) { System.out.println(usage); System.exit(1); } String crawlerName = args[0]; Region region = Region.US_EAST_1; GlueClient glueClient = GlueClient.builder() .region(region) .credentialsProvider(ProfileCredentialsProvider.create()) .build(); getSpecificCrawler(glueClient, crawlerName); glueClient.close(); } public static void getSpecificCrawler(GlueClient glueClient, String crawlerName) { try { GetCrawlerRequest crawlerRequest = GetCrawlerRequest.builder() .name(crawlerName) .build(); GetCrawlerResponse response = glueClient.getCrawler(crawlerRequest); Instant createDate = response.crawler().creationTime(); // Convert the Instant to readable date DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.SHORT ) .withLocale( Locale.US) .withZone( ZoneId.systemDefault() ); formatter.format( createDate ); System.out.println("The create date of the Crawler is " + createDate ); } catch (GlueException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }