public static boolean checkIfBucketExist()

in src/main/java/com/amazonaws/kda/flink/starterkit/SessionUtil.java [64:83]


	public static boolean checkIfBucketExist(String region, String s3Path) {
		boolean bucketExist = false;
		String prefix = "s3a://"; // To use in starts with
		String bktname = s3Path.substring(6);
		bktname = bktname.substring(0, bktname.indexOf("/")); // Extracting S3 Bucket name
		AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(region).build();
		try {
			if (s3Path.startsWith(prefix)) {
				if (s3.doesBucketExistV2(bktname)) {
					bucketExist = true;
					log.info("The provided S3 path exist: " + s3Path);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error("Exceptions received while checking the S3 bucket: " + s3Path);
		}
		s3.shutdown();
		return bucketExist;
	}