用 Amazon Web Services 进行云计算,第 2 部分: 用 Amazon Simple Storage Service (S3) 在云中存储数据
2009-11-05 00:00:00 来源:WEB开发网在新创建的 bucket 和对象上,默认权限指定它们是所有者私有的。可以修改 bucket 的 ACL,向一组用户授予读和写权限,或者对 bucket 的完全控制权。
清单 6. 公开 bucket 及其内容// get the bucket
S3Bucket bucket = getBucketFromName(s3Service, “my bucket”);
// get the ACL
AccessControlList acl = s3Service.getBucketAcl(bucket);
// give everyone read access
acl.grantPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ);
// save changes back to S3
bucket.setAcl(acl);
s3Service.putBucketAcl(bucket);
很容易为 bucket 启用日志记录和获取当前的日志记录状态。启用日志记录之后,会在 S3 中存储这个 bucket 中每个文件的详细访问日志。您的 S3 账户要为日志占用的存储空间付费。
清单 7. S3 bucket 的日志记录// get the bucket
S3Bucket bucket = getBucketFromName(s3Service, “my bucket”);
// is logging enabled?
S3BucketLoggingStatus loggingStatus = s3Service.getBucketLoggingStatus(bucketName);
System.out.println(loggingStatus);
// enable logging
S3BucketLoggingStatus newLoggingStatus = new S3BucketLoggingStatus();
// set a prefix for your log files
newLoggingStatus.setLogfilePrefix(logFilePrefix);
// set the target bucket name
newLoggingStatus.setTargetBucketName(bucketName);
// give the log_delivery group permissions to read and write from the bucket
AccessControlList acl = s3Service.getBucketAcl(bucket);
acl.grantPermission(GroupGrantee.LOG_DELIVERY, Permission.PERMISSION_WRITE);
acl.grantPermission(GroupGrantee.LOG_DELIVERY, Permission.PERMISSION_READ_ACP);
bucket.setAcl(acl);
// save the changed ACL for the bucket to S3
s3Service.putBucketAcl(bucket);
// save the changes to the bucket logging
s3Service.setBucketLoggingStatus(bucketName, newLoggingStatus, true);
System.out.println("The bucket logging status is now enabled.");
- ››web安全之信息刺探防范1
- ››webqq 最新加密算法
- ››webdriver 数据库验证方法
- ››WebSphere Application Server 7.0 XML Feature P...
- ››Web2.0网络时代基于社会影响力的声望值
- ››Web服务器搭建:配置Linux+Apache+Mysql+PHP(或Pe...
- ››WebLogic调整Java虚拟机性能优化参数
- ››webqq2.0协议研究(3)-ClientId生成
- ››Web.config配置文件
- ››WebBrowser组件的execWB方法——Delphi控制浏览器...
- ››Web前端设计模式--制作漂亮的弹出层
- ››WebSphere 反向投资者: 解决 WebSphere Applicati...
更多精彩
赞助商链接