本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
建立具有任務標籤 (用於標示) 的批次作業任務
您可以新增標籤來標記和控制對 Amazon S3 批次操作任務的存取。標籤可用來識別負責批次操作任務的人員。您可以建立已連接標籤的任務,也可以在建立任務後將標籤新增至任務。如需詳細資訊,請參閱使用標籤控制存取和標記任務。
下列 AWS CLI 範例會使用任務標籤作為S3PutObjectCopy
任務的標籤來建立 S3 批次操作任務。
-
選取您要批次操作任務執行的動作或
OPERATION
,然後選擇您的TargetResource
。read -d '' OPERATION <<EOF { "S3PutObjectCopy": { "TargetResource": "arn:aws:s3:::
amzn-s3-demo-destination-bucket
" } } EOF -
識別您要用於任務的
TAGS
。在本例中,您套用兩個標籤,department
和FiscalYear
,分別具有數值Marketing
和2020
。read -d '' TAGS <<EOF [ { "Key": "
department
", "Value": "Marketing
" }, { "Key": "FiscalYear
", "Value": "2020
" } ] EOF -
指定批次操作任務的
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 -
設定批次操作任務的
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 執行
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)" \ --regionus-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(); }