AWS Code Sample

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above. demonstrates how to list all the Amazon Glacier vaults.

/* Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package com.example.glacier; import; import; import; import; import java.util.List; /** * List your Amazon Glacier vaults. * * This code expects that you have AWS credentials set up per: * */ public class ListVaults { public static void main(String[] args) { GlacierClient glacier = GlacierClient.builder().build(); boolean list_complete = false; String new_marker = null; int total_vaults = 0; System.out.println("Your Amazon Glacier vaults:"); while (!list_complete) { ListVaultsResponse response = null; if (new_marker != null) { ListVaultsRequest request = ListVaultsRequest.builder() .marker(new_marker) .build(); response = glacier.listVaults(request); } else { ListVaultsRequest request = ListVaultsRequest.builder() .build(); response = glacier.listVaults(request); } List<DescribeVaultOutput> vault_list = response.vaultList(); for (DescribeVaultOutput v: vault_list) { total_vaults += 1; System.out.println("* " + v.vaultName()); } // check for further results. new_marker = response.marker(); if (new_marker == null) { list_complete = true; } } if (total_vaults == 0) { System.out.println(" no vaults found."); } } }

Sample Details

Service: glacier

Author: soo-aws

Type: full-example

On this page: