Skip to content

Commit

Permalink
Add hello examples to various services (#5698)
Browse files Browse the repository at this point in the history
* add hello examples
  • Loading branch information
scmacdon authored and DavidSouther committed Nov 27, 2023
1 parent 8251285 commit fa3def3
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .doc_gen/metadata/dynamodb_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ dynamodb_Hello:
synopsis: get started using &DDB;.
category: Hello
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/dynamodb
sdkguide:
excerpts:
- description:
snippet_tags:
- dynamodb.java2.list_tables.main
.NET:
versions:
- sdk_version: 3
Expand Down
9 changes: 9 additions & 0 deletions .doc_gen/metadata/glue_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ glue_Hello:
synopsis: get started using &GLU;.
category: Hello
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/glue
sdkguide:
excerpts:
- description:
snippet_tags:
- glue.java2.hello.main
.NET:
versions:
- sdk_version: 3
Expand Down
9 changes: 9 additions & 0 deletions .doc_gen/metadata/iam_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ iam_Hello:
synopsis: get started using &IAM;.
category: Hello
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/iam
sdkguide:
excerpts:
- description:
snippet_tags:
- iam.java2.hello.main
.NET:
versions:
- sdk_version: 3
Expand Down
9 changes: 9 additions & 0 deletions .doc_gen/metadata/s3_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ s3_Hello:
synopsis: get started using &S3;.
category: Hello
languages:
Java:
versions:
- sdk_version: 2
github: javav2/example_code/s3
sdkguide:
excerpts:
- description:
snippet_tags:
- s3.java2.hello.main
Python:
versions:
- sdk_version: 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

package com.example.dynamodb;

// snippet-start:[dynamodb.java2.list_tables.main]
// snippet-start:[dynamodb.java2.list_tables.import]
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.regions.Region;
Expand Down Expand Up @@ -41,9 +42,7 @@ public static void main(String[] args) {
ddb.close();
}

// snippet-start:[dynamodb.java2.list_tables.main]
public static void listAllTables(DynamoDbClient ddb){

boolean moreTables = true;
String lastName = null;

Expand Down
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]
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 javav2/example_code/s3/src/main/java/com/example/s3/HelloS3.java
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]

0 comments on commit fa3def3

Please sign in to comment.