Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Gunakan Operasi Batch S3 dengan mode tata kelola penyimpanan 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 menerapkan tata kelola retensi Kunci Objek S3 dengan tanggal 30 Januari 2025, di retain until
date
beberapa objek. Contoh ini membuat pekerjaan Operasi Batch yang menggunakan bucket manifes dan melaporkan hasilnya di bucket laporan.
Untuk menggunakan contoh berikut, ganti
dengan informasi Anda sendiri. placeholder masukan pengguna
AWS CLI Contoh berikut menunjukkan cara menggunakan Operasi Batch untuk menerapkan mode tata kelola retensi Kunci Objek S3 di beberapa objek.
contoh — Terapkan tata kelola retensi Kunci Objek S3 di beberapa objek dengan penyimpanan hingga tanggal 30 Januari 2025
export AWS_PROFILE='
aws-user
' export AWS_DEFAULT_REGION='us-west-2
' export ACCOUNT_ID=123456789012
export ROLE_ARN='arn:aws:iam::123456789012
:role/batch_operations-objectlock
' read -d ''OPERATION
<<EOF { "S3PutObjectRetention": { "Retention": { "RetainUntilDate":"2025-01-30T00:00:00
", "Mode":"GOVERNANCE" } } } EOF read -d ''MANIFEST
<<EOF { "Spec": { "Format": "S3BatchOperations_CSV_20180820", "Fields": [ "Bucket", "Key" ] }, "Location": { "ObjectArn": "arn:aws:s3:::", "ETag": "
amzn-s3-demo-manifest-bucket
/governance-objects-manifest.csvYour-manifest-ETag
" } } EOF read -d ''REPORT
<<EOF { "Bucket": "arn:aws:s3:::amzn-s3-demo-completion-report-bucket
T", "Format": "Report_CSV_20180820", "Enabled": true, "Prefix": "reports/governance-objects
", "ReportScope": "AllTasks" } EOF aws \ s3control create-job \ --account-id "${ACCOUNT_ID
}" \ --manifest "${MANIFEST
//$'\n'}" \ --operation "${OPERATION
//$'\n'/}" \ --report "${REPORT
//$'\n'}" \ --priority10
\ --role-arn "${ROLE_ARN
}" \ --client-request-token "$(uuidgen)" \ --region "${AWS_DEFAULT_REGION
}" \ --description "Put governance retention
";
contoh — Lewati tata kelola retensi di beberapa objek
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 memintas tata kelola retensi pada beberapa objek dan membuat pekerjaan Operasi Batch yang menggunakan bucket manifes dan melaporkan hasil di bucket laporan.
export AWS_PROFILE='
aws-user
' read -d '' bypass_governance_permissions <<EOF { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:BypassGovernanceRetention" ], "Resource": [ "arn:aws:s3:::amzn-s3-demo-manifest-bucket
/*" ] } ] } EOF aws iam put-role-policy --role-namebatch-operations-objectlock
--policy-namebypass-governance-permissions
--policy-document "${bypass_governance_permissions
}" export AWS_PROFILE='aws-user
' export AWS_DEFAULT_REGION='us-west-2
' export ACCOUNT_ID=123456789012
export ROLE_ARN='arn:aws:iam::123456789012
:role/batch_operations-objectlock
' read -d ''OPERATION
<<EOF { "S3PutObjectRetention": { "BypassGovernanceRetention": true, "Retention": { } } } EOF read -d ''MANIFEST
<<EOF { "Spec": { "Format": "S3BatchOperations_CSV_20180820", "Fields": [ "Bucket", "Key" ] }, "Location": { "ObjectArn": "arn:aws:s3:::", "ETag": "
amzn-s3-demo-manifest-bucket
/governance-objects-manifest.csvYour-manifest-ETag
" } } EOF read -d '' REPORT <<EOF { "Bucket": "arn:aws:s3:::amzn-s3-demo-completion-report-bucket
", "Format": "Report_CSV_20180820", "Enabled": true, "Prefix": "reports/batch_operations-governance
", "ReportScope": "AllTasks" } EOF aws \ s3control create-job \ --account-id "${ACCOUNT_ID
}" \ --manifest "${MANIFEST
//$'\n'}" \ --operation "${OPERATION
//$'\n'/}" \ --report "${REPORT
//$'\n'}" \ --priority10
\ --role-arn "${ROLE_ARN
}" \ --client-request-token "$(uuidgen)" \ --region "${AWS_DEFAULT_REGION
}" \ --description "Remove governance retention
";
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 menerapkan tata kelola retensi Kunci Objek S3 dengan retain until date
set ke 30 Januari 2025 di beberapa objek. Contoh ini membuat pekerjaan Operasi Batch yang menggunakan bucket manifes dan melaporkan hasilnya di bucket laporan.
contoh — Terapkan tata kelola retensi Kunci Objek S3 di beberapa objek dengan penyimpanan hingga tanggal 30 Januari 2025
public String createGovernanceRetentionJob(final AWSS3ControlClient awss3ControlClient) throws ParseException { final String manifestObjectArn = "arn:aws:s3:::
"; final String manifestObjectVersionId = "
amzn-s3-demo-manifest-bucket
/governance-objects-manifest.csv15ad5ba069e6bbc465c77bf83d541385
"; 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:::amzn-s3-demo-completion-report-bucket
"; final String jobReportPrefix = "reports/governance-objects
"; final JobReport jobReport = new JobReport() .withEnabled(true) .withReportScope(JobReportScope.AllTasks) .withBucket(jobReportBucketArn) .withPrefix(jobReportPrefix) .withFormat(JobReportFormat.Report_CSV_20180820); final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); final Date jan30th = format.parse("30/01/2025"); final JobOperation jobOperation = new JobOperation() .withS3PutObjectRetention(new S3SetObjectRetentionOperation() .withRetention(new S3Retention() .withMode(S3ObjectLockRetentionMode.GOVERNANCE) .withRetainUntilDate(jan30th))); final String roleArn = "arn:aws:iam::123456789012
:role/batch_operations-object-lock
"; final Boolean requiresConfirmation = true; final int priority =10
; final CreateJobRequest request = new CreateJobRequest() .withAccountId("123456789012
") .withDescription("Put governance retention
") .withManifest(manifestToPublicApi) .withOperation(jobOperation) .withPriority(priority) .withRoleArn(roleArn) .withReport(jobReport) .withConfirmationRequired(requiresConfirmation); final CreateJobResult result = awss3ControlClient.createJob(request); return result.getJobId(); }
contoh — Lewati tata kelola retensi di beberapa objek
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 mem-bypass tata kelola retensi di beberapa objek dan membuat pekerjaan Operasi Batch yang menggunakan bucket manifes dan melaporkan hasilnya di bucket laporan.
public void allowBypassGovernance() { final String roleName = "
batch_operations-object-lock
"; final String bypassGovernancePermissions = "{" + " \"Version\": \"2012-10-17\"," + " \"Statement\": [" + " {" + " \"Effect\": \"Allow\"," + " \"Action\": [" + " \"s3:BypassGovernanceRetention\"" + " ]," + " \"Resource\": [" + " \"arn:aws:s3:::amzn-s3-demo-manifest-bucket
/*\"" + " ]" + " }" + " ]" + "}"; final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient(); final PutRolePolicyRequest putRolePolicyRequest = new PutRolePolicyRequest() .withPolicyDocument(bypassGovernancePermissions) .withPolicyName("bypass-governance-permissions") .withRoleName(roleName); final PutRolePolicyResult putRolePolicyResult = iam.putRolePolicy(putRolePolicyRequest); } public String createRemoveGovernanceRetentionJob(final AWSS3ControlClient awss3ControlClient) { final String manifestObjectArn = "arn:aws:s3:::"; final String manifestObjectVersionId = "
amzn-s3-demo-manifest-bucket
/governance-objects-manifest.csv15ad5ba069e6bbc465c77bf83d541385
"; 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:::amzn-s3-demo-completion-report-bucket
"; final String jobReportPrefix = "reports/batch_operations-governance
"; final JobReport jobReport = new JobReport() .withEnabled(true) .withReportScope(JobReportScope.AllTasks) .withBucket(jobReportBucketArn) .withPrefix(jobReportPrefix) .withFormat(JobReportFormat.Report_CSV_20180820); final JobOperation jobOperation = new JobOperation() .withS3PutObjectRetention(new S3SetObjectRetentionOperation() .withRetention(new S3Retention())); final String roleArn = "arn:aws:iam::123456789012
:role/batch_operations-object-lock
"; final Boolean requiresConfirmation = true; final int priority =10
; final CreateJobRequest request = new CreateJobRequest() .withAccountId("123456789012
") .withDescription("Remove governance retention
") .withManifest(manifestToPublicApi) .withOperation(jobOperation) .withPriority(priority) .withRoleArn(roleArn) .withReport(jobReport) .withConfirmationRequired(requiresConfirmation); final CreateJobResult result = awss3ControlClient.createJob(request); return result.getJobId(); }