배치 작업을 사용한 객체 잠금 보존 설정 - Amazon Simple Storage Service

배치 작업을 사용한 객체 잠금 보존 설정

다음 예제에서는 규칙에서 매니페스트 버킷의 객체에 대한 S3 객체 잠금 보존을 설정할 수 있도록 허용합니다.

버킷의 객체에 대해 객체 잠금 보존을 실행할 수 있도록 하기 위해 s3:PutObjectRetention 권한을 포함하도록 역할을 업데이트합니다.

export AWS_PROFILE='aws-user' read -d '' retention_permissions <<EOF { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:PutObjectRetention" ], "Resource": [ "arn:aws:s3:::{{ManifestBucket}}/*" ] } ] } EOF aws iam put-role-policy --role-name bops-objectlock --policy-name retention-permissions --policy-document "${retention_permissions}"
public void allowPutObjectRetention() { final String roleName = "bops-object-lock"; final String retentionPermissions = "{" + " \"Version\": \"2012-10-17\"," + " \"Statement\": [" + " {" + " \"Effect\": \"Allow\"," + " \"Action\": [" + " \"s3:PutObjectRetention\"" + " ]," + " \"Resource\": [" + " \"arn:aws:s3:::ManifestBucket*\"" + " ]" + " }" + " ]" + "}"; final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient(); final PutRolePolicyRequest putRolePolicyRequest = new PutRolePolicyRequest() .withPolicyDocument(retentionPermissions) .withPolicyName("retention-permissions") .withRoleName(roleName); final PutRolePolicyResult putRolePolicyResult = iam.putRolePolicy(putRolePolicyRequest); }