启用Amazon s3的access server log功能

默认情况下bucket的日志记录功能没有开启,所以需要手动启用,代码如下:

		String accessKey="";
		String secretKey="";
		AmazonS3 s3=new AmazonS3Client(new BasicAWSCredentials(accessKey,secretKey));
		
		String sourceBucket="";
		String targetBucket="";
		String logFilePrefix="";
		//create targetBucket to collecte and store log files
		s3.createBucket(targetBucket);
		
		//make targetBucket get premission to write log
		CannedAccessControlList acl = CannedAccessControlList.LogDeliveryWrite;
		s3.setBucketAcl(targetBucket, acl);
		
		//make sourceBucket send logs to targetBucket
		BucketLoggingConfiguration blc =new BucketLoggingConfiguration(targetBucket,logFilePrefix);
		SetBucketLoggingConfigurationRequest sblcr=new SetBucketLoggingConfigurationRequest(sourceBucket,blc);
		s3.setBucketLoggingConfiguration(sblcr);
		
		
 

你可能感兴趣的:(Access)