使用用于标记的任务标签创建分批操作任务 - Amazon Simple Storage Service

使用用于标记的任务标签创建分批操作任务

可以通过添加标签 来标注 Amazon S3 批量操作任务和控制对任务的访问。标签可用于确定谁负责分批操作任务。您可以创建附加了标签的任务,并且可以在创建任务后向任务添加标签。有关更多信息,请参阅 使用标签控制访问和标记任务

以下 AWS CLI 示例创建了 S3 分批操作 S3PutObjectCopy 任务,其中使用任务标签作为该任务的标签。

  1. 请选择您希望分批操作任务执行的操作或 OPERATION,然后选择您的 TargetResource

    read -d '' OPERATION <<EOF { "S3PutObjectCopy": { "TargetResource": "arn:aws:s3:::amzn-s3-demo-destination-bucket" } } EOF
  2. 确定您需要用于此任务的任务 TAGS。在这种情况下,您应用两个标签 departmentFiscalYear,值分别为 Marketing2020

    read -d '' TAGS <<EOF [ { "Key": "department", "Value": "Marketing" }, { "Key": "FiscalYear", "Value": "2020" } ] EOF
  3. 为分批操作任务指定 MANIFEST

    read -d '' MANIFEST <<EOF { "Spec": { "Format": "EXAMPLE_S3BatchOperations_CSV_20180820", "Fields": [ "Bucket", "Key" ] }, "Location": { "ObjectArn": "arn:aws:s3:::amzn-s3-demo-manifest-bucket/example_manifest.csv", "ETag": "example-5dc7a8bfb90808fc5d546218" } } EOF
  4. 为分批操作任务配置 REPORT

    read -d '' REPORT <<EOF { "Bucket": "arn:aws:s3:::amzn-s3-demo-completion-report-bucket", "Format": "Example_Report_CSV_20180820", "Enabled": true, "Prefix": "reports/copy-with-replace-metadata", "ReportScope": "AllTasks" } EOF
  5. 运行 create-job 操作以使用在上述步骤中设置的输入创建分批操作任务。

    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)" \ --region us-west-2 \ --description "Copy with Replace Metadata";

以下示例使用 AWS SDK for Java 创建带有标签的 S3 分批操作任务。

public String createJob(final AWSS3ControlClient awss3ControlClient) { final String manifestObjectArn = "arn:aws:s3:::amzn-s3-demo-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:::amzn-s3-demo-completion-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(); }