Menggunakan Operasi Batch S3 untuk menonaktifkan penahanan hukum Kunci Objek S3 - Amazon Simple Storage Service

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Menggunakan Operasi Batch S3 untuk menonaktifkan penahanan hukum Kunci Objek S3

Contoh berikut dibangun berdasarkan contoh sebelumnya tentang pembuatan kebijakan kepercayaan, dan pengaturan izin konfigurasi Operasi Batch S3 serta Kunci Objek S3. Contoh ini menunjukkan cara menonaktifkan penahanan hukum Kunci Objek pada objek menggunakan Operasi Batch.

Contoh ini pertama-tama akan memperbarui peran untuk memberikan izin s3:PutObjectLegalHold, membuat pekerjaan Operasi Batch yang menonaktifkan (menghapus) penahanan hukum dari objek yang diidentifikasi dalam manifes, kemudian melaporkan hal tersebut.

contoh Memperbarui peran untuk memberikan izin s3:PutObjectLegalHold
export AWS_PROFILE='aws-user' read -d '' legal_hold_permissions <<EOF { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:PutObjectLegalHold" ], "Resource": [ "arn:aws:s3:::ManifestBucket/*" ] } ] EOF aws iam put-role-policy --role-name bops-objectlock --policy-name legal-hold-permissions --policy-document "${legal_hold_permissions}"
contoh Menonaktifkan penahanan hukum

Contoh berikut menunjukkan cara menonaktifkan penahanan hukum.

export AWS_PROFILE='aws-user' export AWS_DEFAULT_REGION='us-west-2' export ACCOUNT_ID=123456789012 export ROLE_ARN='arn:aws:iam::123456789012:role/bops-objectlock' read -d '' OPERATION <<EOF { "S3PutObjectLegalHold": { "LegalHold": { "Status":"OFF" } } } EOF read -d '' MANIFEST <<EOF { "Spec": { "Format": "S3BatchOperations_CSV_20180820", "Fields": [ "Bucket", "Key" ] }, "Location": { "ObjectArn": "arn:aws:s3:::ManifestBucket/legalhold-object-manifest.csv", "ETag": "Your-manifest-ETag" } } EOF read -d '' REPORT <<EOF { "Bucket": "arn:aws:s3:::ReportBucket", "Format": "Report_CSV_20180820", "Enabled": true, "Prefix": "reports/legalhold-objects-bops", "ReportScope": "AllTasks" } EOF aws \ s3control create-job \ --account-id "${ACCOUNT_ID}" \ --manifest "${MANIFEST//$'\n'}" \ --operation "${OPERATION//$'\n'/}" \ --report "${REPORT//$'\n'}" \ --priority 10 \ --role-arn "${ROLE_ARN}" \ --client-request-token "$(uuidgen)" \ --region "${AWS_DEFAULT_REGION}" \ --description "Turn off legal hold";
contoh Memperbarui peran untuk memberikan izin s3:PutObjectLegalHold
public void allowPutObjectLegalHold() { final String roleName = "bops-object-lock"; final String legalHoldPermissions = "{" + " \"Version\": \"2012-10-17\"," + " \"Statement\": [" + " {" + " \"Effect\": \"Allow\"," + " \"Action\": [" + " \"s3:PutObjectLegalHold\"" + " ]," + " \"Resource\": [" + " \"arn:aws:s3:::ManifestBucket/*\"" + " ]" + " }" + " ]" + "}"; final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient(); final PutRolePolicyRequest putRolePolicyRequest = new PutRolePolicyRequest() .withPolicyDocument(legalHoldPermissions) .withPolicyName("legal-hold-permissions") .withRoleName(roleName); final PutRolePolicyResult putRolePolicyResult = iam.putRolePolicy(putRolePolicyRequest); }
contoh Menonaktifkan penahanan hukum

Gunakan contoh di bawah ini jika Anda ingin menonaktifkan penahanan hukum.

public String createLegalHoldOffJob(final AWSS3ControlClient awss3ControlClient) { final String manifestObjectArn = "arn:aws:s3:::ManifestBucket/legalhold-object-manifest.csv"; final String manifestObjectVersionId = "15ad5ba069e6bbc465c77bf83d541385"; final JobManifestLocation manifestLocation = new JobManifestLocation() .withObjectArn(manifestObjectArn) .withETag(manifestObjectVersionId); final JobManifestSpec manifestSpec = new JobManifestSpec() .withFormat(JobManifestFormat.S3BatchOperations_CSV_20180820) .withFields("Bucket", "Key"); final JobManifest manifestToPublicApi = new JobManifest() .withLocation(manifestLocation) .withSpec(manifestSpec); final String jobReportBucketArn = "arn:aws:s3:::ReportBucket"; final String jobReportPrefix = "reports/legalhold-objects-bops"; final JobReport jobReport = new JobReport() .withEnabled(true) .withReportScope(JobReportScope.AllTasks) .withBucket(jobReportBucketArn) .withPrefix(jobReportPrefix) .withFormat(JobReportFormat.Report_CSV_20180820); final JobOperation jobOperation = new JobOperation() .withS3PutObjectLegalHold(new S3SetObjectLegalHoldOperation() .withLegalHold(new S3ObjectLockLegalHold() .withStatus(S3ObjectLockLegalHoldStatus.OFF))); final String roleArn = "arn:aws:iam::123456789012:role/bops-object-lock"; final Boolean requiresConfirmation = true; final int priority = 10; final CreateJobRequest request = new CreateJobRequest() .withAccountId("123456789012") .withDescription("Turn off legal hold") .withManifest(manifestToPublicApi) .withOperation(jobOperation) .withPriority(priority) .withRoleArn(roleArn) .withReport(jobReport) .withConfirmationRequired(requiresConfirmation); final CreateJobResult result = awss3ControlClient.createJob(request); return result.getJobId(); }