可用区
更新时间:2024-07-02
查询可用区列表
如下代码可以查询当前region下的可用区(zone)列表信息:
import com.baidubce.BceClientConfiguration;
import com.baidubce.Protocol;
import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.bcc.BccClient;
import com.baidubce.services.bcc.BccClientConfiguration;
import com.baidubce.services.bcc.model.zone.ZoneModel;
import com.baidubce.services.bcc.model.zone.ListZonesResponse;
public class Main {
public static void main(String[] args) {
// 设置您的ak、sk和要访问的endpoint
String endpoint = "bcc.bj.baidubce.com";
String ak = "ak";
String sk = "sk";
// 设置默认配置
BceClientConfiguration bccClientConfiguration = new BccClientConfiguration()
.withProtocol(Protocol.HTTP)
.withCredentials(new DefaultBceCredentials(ak, sk))
.withEndpoint(endpoint);
// 创建bcc client
BccClient bccClient = new BccClient(bccClientConfiguration);
ListZonesResponse listZonesResponse = bccClient.listZones();
for (ZoneModel zoneModel : listZonesResponse.getZones()) {
System.out.println(zoneModel.getZoneName());
}
}
}