-
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.
Add hello examples to various services (#5698)
* add hello examples
- Loading branch information
1 parent
8251285
commit fa3def3
Showing
8 changed files
with
168 additions
and
2 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
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
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
39 changes: 39 additions & 0 deletions
39
javav2/example_code/glue/src/main/java/com/example/glue/HelloGlue.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,39 @@ | ||
//snippet-sourcedescription:[GetDatabase.java demonstrates how to get a database.] | ||
//snippet-keyword:[AWS SDK for Java v2] | ||
//snippet-keyword:[AWS Glue] | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
//snippet-start:[glue.java2.hello.main] | ||
package com.example.glue; | ||
|
||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.glue.GlueClient; | ||
import software.amazon.awssdk.services.glue.model.ListJobsRequest; | ||
import software.amazon.awssdk.services.glue.model.ListJobsResponse; | ||
import java.util.List; | ||
|
||
public class HelloGlue { | ||
|
||
public static void main(String[] args){ | ||
GlueClient glueClient = GlueClient.builder() | ||
.region(Region.US_EAST_1) | ||
.build(); | ||
|
||
listJobs(glueClient); | ||
} | ||
|
||
public static void listJobs(GlueClient glueClient) { | ||
ListJobsRequest request = ListJobsRequest.builder() | ||
.maxResults(10) | ||
.build(); | ||
ListJobsResponse response = glueClient.listJobs(request); | ||
List<String> jobList = response.jobNames(); | ||
jobList.forEach(job -> { | ||
System.out.println("Job Name: " + job); | ||
}); | ||
} | ||
} | ||
//snippet-end:[glue.java2.hello.main] |
43 changes: 43 additions & 0 deletions
43
javav2/example_code/iam/src/main/java/com/example/iam/HelloIAM.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,43 @@ | ||
//snippet-sourcedescription:[HelloIAM.java demonstrates how to list AWS Identity and Access Management (IAM) policies.] | ||
//snippet-keyword:[AWS SDK for Java v2] | ||
//snippet-service:[IAM] | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.example.iam; | ||
|
||
// snippet-start:[iam.java2.hello.main] | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.iam.IamClient; | ||
import software.amazon.awssdk.services.iam.model.ListPoliciesResponse; | ||
import software.amazon.awssdk.services.iam.model.Policy; | ||
import java.util.List; | ||
|
||
/** | ||
* 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 HelloIAM { | ||
public static void main(String[] args){ | ||
Region region = Region.AWS_GLOBAL; | ||
IamClient iam = IamClient.builder() | ||
.region(region) | ||
.build(); | ||
|
||
listPolicies(iam); | ||
} | ||
|
||
public static void listPolicies(IamClient iam) { | ||
ListPoliciesResponse response = iam.listPolicies(); | ||
List<Policy> polList = response.policies(); | ||
polList.forEach(policy -> { | ||
System.out.println("Policy Name: " + policy.policyName()); | ||
}); | ||
} | ||
} | ||
// snippet-end:[iam.java2.hello.main] |
49 changes: 49 additions & 0 deletions
49
javav2/example_code/s3/src/main/java/com/example/s3/HelloS3.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,49 @@ | ||
//snippet-sourcedescription:[HelloS3.java demonstrates how to list your Amazon Simple Storage Service (Amazon S3) buckets.] | ||
//snippet-keyword:[AWS SDK for Java v2] | ||
//snippet-service:[Amazon S3] | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.example.s3; | ||
|
||
// snippet-start:[s3.java2.hello.main] | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.model.Bucket; | ||
import software.amazon.awssdk.services.s3.model.ListBucketsResponse; | ||
import software.amazon.awssdk.services.s3.model.S3Exception; | ||
import java.util.List; | ||
|
||
/** | ||
* 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 HelloS3 { | ||
public static void main(String[] args) { | ||
Region region = Region.US_EAST_1; | ||
S3Client s3 = S3Client.builder() | ||
.region(region) | ||
.build(); | ||
|
||
listBuckets(s3); | ||
} | ||
|
||
public static void listBuckets(S3Client s3) { | ||
try { | ||
ListBucketsResponse response = s3.listBuckets(); | ||
List<Bucket> bucketList = response.buckets(); | ||
bucketList.forEach(bucket -> { | ||
System.out.println("Bucket Name: " + bucket.name()); | ||
}); | ||
|
||
} catch (S3Exception e) { | ||
System.err.println(e.awsErrorDetails().errorMessage()); | ||
System.exit(1); | ||
} | ||
} | ||
} | ||
// snippet-end:[s3.java2.hello.main] |