-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dotnet-version-updates-pt1' of github.com:rlhagerm/aws-…
…doc-sdk-examples into dotnet-version-updates-pt1
- Loading branch information
Showing
4 changed files
with
120 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
javav2/example_code/s3/src/main/java/com/example/s3/CreateGovernanceRetentionJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
package com.example.s3; | ||
|
||
|
||
import software.amazon.awssdk.services.s3control.S3ControlClient; | ||
import software.amazon.awssdk.services.s3control.model.*; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
|
||
// snippet-start:[s3.java2.create_governance_retemtion.main] | ||
/** | ||
* Before running this Java V2 code example, set up your development | ||
* environment, including your credentials. | ||
* | ||
* For more information, see the following documentation topic: | ||
* | ||
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html | ||
*/ | ||
public class CreateGovernanceRetentionJob { | ||
|
||
public static void main(String[]args) throws ParseException { | ||
final String usage = """ | ||
Usage: | ||
<manifestObjectArn> <jobReportBucketArn> <roleArn> <accountId> <manifestObjectVersionId> | ||
Where: | ||
manifestObjectArn - The Amazon Resource Name (ARN) of the S3 object that contains the manifest file for the governance objects.\s | ||
bucketName - The ARN of the S3 bucket where the job report will be stored. | ||
roleArn - The ARN of the IAM role that will be used to perform the governance retention operation. | ||
accountId - Your AWS account Id. | ||
manifestObjectVersionId = A unique value that is used as the `eTag` property of the `JobManifestLocation` object. | ||
"""; | ||
|
||
if (args.length != 4) { | ||
System.out.println(usage); | ||
return; | ||
} | ||
|
||
String manifestObjectArn = args[0]; | ||
String jobReportBucketArn = args[1]; | ||
String roleArn = args[2]; | ||
String accountId = args[3]; | ||
String manifestObjectVersionId = args[4]; | ||
|
||
S3ControlClient s3ControlClient = S3ControlClient.create(); | ||
createGovernanceRetentionJob(s3ControlClient, manifestObjectArn, jobReportBucketArn, roleArn, accountId, manifestObjectVersionId); | ||
} | ||
|
||
public static String createGovernanceRetentionJob(final S3ControlClient s3ControlClient, String manifestObjectArn, String jobReportBucketArn, String roleArn, String accountId, String manifestObjectVersionId) throws ParseException { | ||
final JobManifestLocation manifestLocation = JobManifestLocation.builder() | ||
.objectArn(manifestObjectArn) | ||
.eTag(manifestObjectVersionId) | ||
.build(); | ||
|
||
final JobManifestSpec manifestSpec = JobManifestSpec.builder() | ||
.format(JobManifestFormat.S3_BATCH_OPERATIONS_CSV_20180820) | ||
.fields(Arrays.asList(JobManifestFieldName.BUCKET, JobManifestFieldName.KEY)) | ||
.build(); | ||
|
||
final JobManifest manifestToPublicApi = JobManifest.builder() | ||
.location(manifestLocation) | ||
.spec(manifestSpec) | ||
.build(); | ||
|
||
final String jobReportPrefix = "reports/governance-objects"; | ||
final JobReport jobReport = JobReport.builder() | ||
.enabled(true) | ||
.reportScope(JobReportScope.ALL_TASKS) | ||
.bucket(jobReportBucketArn) | ||
.prefix(jobReportPrefix) | ||
.format(JobReportFormat.REPORT_CSV_20180820) | ||
.build(); | ||
|
||
final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); | ||
final Date jan30th = format.parse("30/01/2025"); | ||
|
||
final S3SetObjectRetentionOperation s3SetObjectRetentionOperation = S3SetObjectRetentionOperation.builder() | ||
.retention(S3Retention.builder() | ||
.mode(S3ObjectLockRetentionMode.GOVERNANCE) | ||
.retainUntilDate(jan30th.toInstant()) | ||
.build()) | ||
.build(); | ||
|
||
final JobOperation jobOperation = JobOperation.builder() | ||
.s3PutObjectRetention(s3SetObjectRetentionOperation) | ||
.build(); | ||
|
||
final Boolean requiresConfirmation = true; | ||
final int priority = 10; | ||
|
||
final CreateJobRequest request = CreateJobRequest.builder() | ||
.accountId(accountId) | ||
.description("Put governance retention") | ||
.manifest(manifestToPublicApi) | ||
.operation(jobOperation) | ||
.priority(priority) | ||
.roleArn(roleArn) | ||
.report(jobReport) | ||
.confirmationRequired(requiresConfirmation) | ||
.build(); | ||
|
||
final CreateJobResponse result = s3ControlClient.createJob(request); | ||
return result.jobId(); | ||
} | ||
} | ||
// snippet-end:[s3.java2.create_governance_retemtion.main] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters