Usar operações em lote do S3 com o modo de conformidade de retenção do bloqueio de objetos do S3
O exemplo a seguir baseia-se nos exemplos anteriores de criação de uma política de confiança e na definição de permissões de configuração do Operações em lote do S3 e Bloqueio de objetos do S3 em seus objetos. Este exemplo define o modo de retenção como COMPLIANCE
e retain
until date
como 1.º de janeiro de 2025. Esse exemplo cria um trabalho que visa objetos no bucket de manifesto e relata os resultados no bucket de relatórios identificado.
Para usar os exemplos a seguir, substitua
por suas próprias informações. user input
placeholders
Os exemplos da AWS CLI a seguir mostram como usar o Operações em Lote para aplicar o modo de conformidade de retenção do Bloqueio de Objetos do S3 a vários objetos.
exemplo – Definir o modo de conformidade de retenção do Bloqueio de Objetos do S3 em vários objetos
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-01T00:00:00
", "Mode":"COMPLIANCE" } } } EOF read -d ''MANIFEST
<<EOF { "Spec": { "Format": "S3BatchOperations_CSV_20180820", "Fields": [ "Bucket", "Key" ] }, "Location": { "ObjectArn": "arn:aws:s3:::", "ETag": "
amzn-s3-demo-manifest-bucket
/compliance-objects-manifest.csvYour-manifest-ETag
" } } EOF read -d ''REPORT
<<EOF { "Bucket": "arn:aws:s3:::ReportBucket
", "Format": "Report_CSV_20180820", "Enabled": true, "Prefix": "", "ReportScope": "AllTasks" } EOF aws \ s3control create-job \ --account-id "${
amzn-s3-demo-completion-report-bucket
/compliance-objects-batch-operationsACCOUNT_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 "Set compliance retain-until to 1 Jul 2030
";
exemplo – Estender o retain until
date
do modo de COMPLIANCE
para 15 de janeiro de 2025
O exemplo a seguir estende a retain until date
do modo de COMPLIANCE
para 15 de janeiro de 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-15T00:00:00
", "Mode":"COMPLIANCE" } } } EOF read -d ''MANIFEST
<<EOF { "Spec": { "Format": "S3BatchOperations_CSV_20180820", "Fields": [ "Bucket", "Key" ] }, "Location": { "ObjectArn": "arn:aws:s3:::", "ETag": "
amzn-s3-demo-manifest-bucket
/compliance-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/compliance-objects-batch_operations
", "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 "Extend compliance retention to 15 Jan 2025
";
Os exemplos da AWS SDK for Java a seguir mostram como usar o Operações em Lote para aplicar o modo de conformidade de retenção do Bloqueio de Objetos do S3 a vários objetos.
exemplo – Definir o modo de retenção como COMPLIANCE e o prazo de retenção para 1.º de janeiro de 2025
public String createComplianceRetentionJob(final AWSS3ControlClient awss3ControlClient) throws ParseException { final String manifestObjectArn = "arn:aws:s3:::
"; final String manifestObjectVersionId = "
amzn-s3-demo-manifest-bucket
/compliance-objects-manifest.csvyour-object-version-Id
"; 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/compliance-objects-bops
"; 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 janFirst = format.parse("01/01/2025
"); final JobOperation jobOperation = new JobOperation() .withS3PutObjectRetention(new S3SetObjectRetentionOperation() .withRetention(new S3Retention() .withMode(S3ObjectLockRetentionMode.COMPLIANCE) .withRetainUntilDate(janFirst))); 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("Set compliance retain-until to 1 Jan 2025
") .withManifest(manifestToPublicApi) .withOperation(jobOperation) .withPriority(priority) .withRoleArn(roleArn) .withReport(jobReport) .withConfirmationRequired(requiresConfirmation); final CreateJobResult result = awss3ControlClient.createJob(request); return result.getJobId(); }
exemplo – Estender o retain until
date
do modo COMPLIANCE
O exemplo a seguir estende o retain until date
do modo de COMPLIANCE
para 15 de janeiro de 2025.
public String createExtendComplianceRetentionJob(final AWSS3ControlClient awss3ControlClient) throws ParseException { final String manifestObjectArn = "arn:aws:s3:::
"; final String manifestObjectVersionId = "
amzn-s3-demo-manifest-bucket
/compliance-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/compliance-objects-batch_operations
"; 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 jan15th = format.parse("15/01/2025
"); final JobOperation jobOperation = new JobOperation() .withS3PutObjectRetention(new S3SetObjectRetentionOperation() .withRetention(new S3Retention() .withMode(S3ObjectLockRetentionMode.COMPLIANCE) .withRetainUntilDate(jan15th))); 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("Extend compliance retention to 15 Jan 2025
") .withManifest(manifestToPublicApi) .withOperation(jobOperation) .withPriority(priority) .withRoleArn(roleArn) .withReport(jobReport) .withConfirmationRequired(requiresConfirmation); final CreateJobResult result = awss3ControlClient.createJob(request); return result.getJobId(); }