Skip to content

Commit 255ab73

Browse files
committed
Merge branch 'dotnet-version-updates-pt1' of github.com:rlhagerm/aws-doc-sdk-examples into dotnet-version-updates-pt1
2 parents d8a5990 + 8a00d3b commit 255ab73

File tree

4 files changed

+120
-6
lines changed

4 files changed

+120
-6
lines changed

.doc_gen/metadata/s3-control_metadata.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ s3-control_CreateJob:
3232
- s3control.java2.create_job.compliance.main
3333
- description: Create a legal hold off job.
3434
snippet_tags:
35-
- s3control.java2.create_job.compliance.main
35+
- s3control.java2.create_job.compliance.main
36+
- description: Create a new governance retemtion job.
37+
snippet_tags:
38+
- s3.java2.create_governance_retemtion.main
3639
services:
3740
s3-control: {CreateJob}
3841
s3-control_PutJobTagging:

javascriptv3/example_code/glue/scenarios/basic/steps/start-job-run.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ const waitForJobRun = async (getJobRun, jobName, jobRunId) => {
2323
case "FAILED":
2424
case "TIMEOUT":
2525
case "STOPPED":
26+
case "ERROR":
2627
throw new Error(
2728
`Job ${JobRun.JobRunState}. Error: ${JobRun.ErrorMessage}`,
2829
);
29-
case "RUNNING":
30-
break;
3130
case "SUCCEEDED":
3231
return;
3332
default:
34-
throw new Error(`Unknown job run state: ${JobRun.JobRunState}`);
33+
break;
3534
}
3635

3736
log(
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
5+
package com.example.s3;
6+
7+
8+
import software.amazon.awssdk.services.s3control.S3ControlClient;
9+
import software.amazon.awssdk.services.s3control.model.*;
10+
import java.text.ParseException;
11+
import java.text.SimpleDateFormat;
12+
import java.util.Arrays;
13+
import java.util.Date;
14+
15+
// snippet-start:[s3.java2.create_governance_retemtion.main]
16+
/**
17+
* Before running this Java V2 code example, set up your development
18+
* environment, including your credentials.
19+
*
20+
* For more information, see the following documentation topic:
21+
*
22+
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
23+
*/
24+
public class CreateGovernanceRetentionJob {
25+
26+
public static void main(String[]args) throws ParseException {
27+
final String usage = """
28+
29+
Usage:
30+
<manifestObjectArn> <jobReportBucketArn> <roleArn> <accountId> <manifestObjectVersionId>
31+
32+
Where:
33+
manifestObjectArn - The Amazon Resource Name (ARN) of the S3 object that contains the manifest file for the governance objects.\s
34+
bucketName - The ARN of the S3 bucket where the job report will be stored.
35+
roleArn - The ARN of the IAM role that will be used to perform the governance retention operation.
36+
accountId - Your AWS account Id.
37+
manifestObjectVersionId = A unique value that is used as the `eTag` property of the `JobManifestLocation` object.
38+
""";
39+
40+
if (args.length != 4) {
41+
System.out.println(usage);
42+
return;
43+
}
44+
45+
String manifestObjectArn = args[0];
46+
String jobReportBucketArn = args[1];
47+
String roleArn = args[2];
48+
String accountId = args[3];
49+
String manifestObjectVersionId = args[4];
50+
51+
S3ControlClient s3ControlClient = S3ControlClient.create();
52+
createGovernanceRetentionJob(s3ControlClient, manifestObjectArn, jobReportBucketArn, roleArn, accountId, manifestObjectVersionId);
53+
}
54+
55+
public static String createGovernanceRetentionJob(final S3ControlClient s3ControlClient, String manifestObjectArn, String jobReportBucketArn, String roleArn, String accountId, String manifestObjectVersionId) throws ParseException {
56+
final JobManifestLocation manifestLocation = JobManifestLocation.builder()
57+
.objectArn(manifestObjectArn)
58+
.eTag(manifestObjectVersionId)
59+
.build();
60+
61+
final JobManifestSpec manifestSpec = JobManifestSpec.builder()
62+
.format(JobManifestFormat.S3_BATCH_OPERATIONS_CSV_20180820)
63+
.fields(Arrays.asList(JobManifestFieldName.BUCKET, JobManifestFieldName.KEY))
64+
.build();
65+
66+
final JobManifest manifestToPublicApi = JobManifest.builder()
67+
.location(manifestLocation)
68+
.spec(manifestSpec)
69+
.build();
70+
71+
final String jobReportPrefix = "reports/governance-objects";
72+
final JobReport jobReport = JobReport.builder()
73+
.enabled(true)
74+
.reportScope(JobReportScope.ALL_TASKS)
75+
.bucket(jobReportBucketArn)
76+
.prefix(jobReportPrefix)
77+
.format(JobReportFormat.REPORT_CSV_20180820)
78+
.build();
79+
80+
final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
81+
final Date jan30th = format.parse("30/01/2025");
82+
83+
final S3SetObjectRetentionOperation s3SetObjectRetentionOperation = S3SetObjectRetentionOperation.builder()
84+
.retention(S3Retention.builder()
85+
.mode(S3ObjectLockRetentionMode.GOVERNANCE)
86+
.retainUntilDate(jan30th.toInstant())
87+
.build())
88+
.build();
89+
90+
final JobOperation jobOperation = JobOperation.builder()
91+
.s3PutObjectRetention(s3SetObjectRetentionOperation)
92+
.build();
93+
94+
final Boolean requiresConfirmation = true;
95+
final int priority = 10;
96+
97+
final CreateJobRequest request = CreateJobRequest.builder()
98+
.accountId(accountId)
99+
.description("Put governance retention")
100+
.manifest(manifestToPublicApi)
101+
.operation(jobOperation)
102+
.priority(priority)
103+
.roleArn(roleArn)
104+
.report(jobReport)
105+
.confirmationRequired(requiresConfirmation)
106+
.build();
107+
108+
final CreateJobResponse result = s3ControlClient.createJob(request);
109+
return result.jobId();
110+
}
111+
}
112+
// snippet-end:[s3.java2.create_governance_retemtion.main]

javav2/example_code/s3/src/main/java/com/example/s3/LifecycleConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public static void main(String[] args) {
7474
*/
7575
public static void setLifecycleConfig(S3Client s3, String bucketName, String accountId) {
7676
try {
77-
// Create a rule to archive objects with the "glacierobjects/" prefix to Amazon
78-
// S3 Glacier.
77+
// Create a rule to archive objects with the "glacierobjects/" prefix to the
78+
// S3 Glacier Flexible Retrieval storage class immediately.
7979
LifecycleRuleFilter ruleFilter = LifecycleRuleFilter.builder()
8080
.prefix("glacierobjects/")
8181
.build();

0 commit comments

Comments
 (0)