DeleteHostedZone.java - AWS Code Sample

DeleteHostedZone.java

DeleteHostedZone.java demonstrates how to delete a hosted zone.

Note

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 Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ package com.example.route; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.route53.Route53Client; import software.amazon.awssdk.services.route53.model.DeleteHostedZoneRequest; import software.amazon.awssdk.services.route53.model.Route53Exception; /** * To run this Java V2 code example, ensure that you have setup your development environment, including your credentials. * * For information, see this documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class DeleteHostedZone { public static void main(String[] args) { final String USAGE = "\n" + "Usage:\n" + " DeleteHostedZone <hostedZoneId> \n\n" + "Where:\n" + " hostedZoneId - the hosted zone id. \n"; if (args.length < 1) { System.out.println(USAGE); System.exit(1); } String hostedZoneId = args[0]; Region region = Region.AWS_GLOBAL; Route53Client route53Client = Route53Client.builder() .region(region) .build(); delHostedZone(route53Client, hostedZoneId) ; route53Client.close(); } public static void delHostedZone(Route53Client route53Client, String hostedZoneId ) { try { DeleteHostedZoneRequest deleteHostedZoneRequestRequest = DeleteHostedZoneRequest.builder() .id(hostedZoneId) .build(); route53Client.deleteHostedZone(deleteHostedZoneRequestRequest); System.out.println("The hosted zone was deleted"); } catch (Route53Exception e) { System.err.println(e.getMessage()); System.exit(1); } } }

Sample Details

Service: Amazon Route 53

Last tested: 2020-09-28

Author: AWS - scmacdon

Type: full-example