Creación de un trabajo de Operaciones por lotes con etiquetas de trabajo como etiquetado
Para etiquetar y controlar el acceso a los trabajos de Operaciones por lotes de S3, puede añadir etiquetas. Las etiquetas se pueden utilizar para identificar quién es el responsable de un trabajo de Operaciones por lotes. Puede crear trabajos con etiquetas asociadas a ellos y agregar etiquetas a los trabajos después de que se hayan creado. Para obtener más información, consulte Controlar el acceso y etiquetar trabajos usando etiquetas.
En el siguiente ejemplo de la AWS CLI, se crea un trabajo de S3PutObjectCopy
de la herramienta de operaciones por lotes de S3 mediante el uso de etiquetas de trabajo como marca de trabajo.
-
Seleccione la acción o el valor
OPERATION
que quiera que realice el trabajo de Operaciones por lotes y seleccione el valorTargetResource
.read -d '' OPERATION <<EOF { "S3PutObjectCopy": { "TargetResource": "arn:aws:s3:::destination-bucket" } } EOF
-
Identifique la tarea
TAGS
que quiera para el trabajo. En este caso, se aplican dos etiquetas,department
yFiscalYear
, con los valoresMarketing
y2020
respectivamente.read -d '' TAGS <<EOF [ { "Key": "
department
", "Value": "Marketing
" }, { "Key": "FiscalYear
", "Value": "2020
" } ] EOF -
Especifique el valor
MANIFEST
para el trabajo de Operaciones por lotes.read -d '' MANIFEST <<EOF { "Spec": { "Format": "
EXAMPLE_S3BatchOperations_CSV_20180820
", "Fields": [ "Bucket", "Key" ] }, "Location": { "ObjectArn": "arn:aws:s3:::example-bucket/example_manifest.csv
", "ETag": "example-5dc7a8bfb90808fc5d546218
" } } EOF -
Configure el valor
REPORT
para el trabajo de Operaciones por lotes.read -d '' REPORT <<EOF { "Bucket": "arn:aws:s3:::
example-report-bucket
", "Format": "Example_Report_CSV_20180820
", "Enabled": true, "Prefix": "reports/copy-with-replace-metadata
", "ReportScope": "AllTasks" } EOF Ejecute la acción
create-job
para crear su trabajo de Operaciones por lotes con los datos de entrada establecidos en los pasos previos.aws \ s3control create-job \ --account-id
123456789012
\ --manifest "${MANIFEST//$'\n'}" \ --operation "${OPERATION//$'\n'/}" \ --report "${REPORT//$'\n'}" \ --priority 10 \ --role-arn arn:aws:iam::123456789012
:role/batch-operations-role
\ --tags "${TAGS//$'\n'/}" \ --client-request-token "$(uuidgen)" \ --regionus-west-2
\ --description "Copy with Replace Metadata
";
En el siguiente ejemplo, se crea un trabajo de la herramienta de operaciones por lotes de S3 con etiquetas mediante AWS SDK for Java.
public String createJob(final AWSS3ControlClient awss3ControlClient) { final String manifestObjectArn = "arn:aws:s3:::
example-manifest-bucket/manifests/10_manifest
.csv"; final String manifestObjectVersionId = "example-5dc7a8bfb90808fc5d546218
"; final JobManifestLocation manifestLocation = new JobManifestLocation() .withObjectArn(manifestObjectArn) .withETag(manifestObjectVersionId); final JobManifestSpec manifestSpec = new JobManifestSpec().withFormat(JobManifestFormat.S3InventoryReport_CSV_20161130); final JobManifest manifestToPublicApi = new JobManifest() .withLocation(manifestLocation) .withSpec(manifestSpec); final String jobReportBucketArn = "arn:aws:s3:::example
-report-bucket"; final String jobReportPrefix = "example-job-reports
"; final JobReport jobReport = new JobReport() .withEnabled(true) .withReportScope(JobReportScope.AllTasks) .withBucket(jobReportBucketArn) .withPrefix(jobReportPrefix) .withFormat(JobReportFormat.Report_CSV_20180820); final String lambdaFunctionArn = "arn:aws:lambda:us-west-2
:123456789012
:function:example-function
"; final JobOperation jobOperation = new JobOperation() .withLambdaInvoke(new LambdaInvokeOperation().withFunctionArn(lambdaFunctionArn)); final S3Tag departmentTag = new S3Tag().withKey("department
").withValue("Marketing
"); final S3Tag fiscalYearTag = new S3Tag().withKey("FiscalYear
").withValue("2020
"); final String roleArn = "arn:aws:iam::123456789012
:role/example-batch-operations-role
"; final Boolean requiresConfirmation = true; final int priority = 10; final CreateJobRequest request = new CreateJobRequest() .withAccountId("123456789012
") .withDescription("Test lambda job
") .withManifest(manifestToPublicApi) .withOperation(jobOperation) .withPriority(priority) .withRoleArn(roleArn) .withReport(jobReport) .withTags(departmentTag, fiscalYearTag) .withConfirmationRequired(requiresConfirmation); final CreateJobResult result = awss3ControlClient.createJob(request); return result.getJobId(); }