Skip to content

Commit b9c64bf

Browse files
authored
Move examples into subdirectory
Co-authored-by: Dennis Traub <traubd@amazon.de>
1 parent 0f5999a commit b9c64bf

File tree

4 files changed

+129
-3
lines changed

4 files changed

+129
-3
lines changed

example_code/.gitignore

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
# Compiled class file
7+
*.class
8+
9+
# Log file
10+
*.log
11+
12+
# BlueJ files
13+
*.ctxt
14+
15+
# Mobile Tools for Java (J2ME)
16+
.mtj.tmp/
17+
18+
# Package Files #
19+
*.jar
20+
*.war
21+
*.nar
22+
*.ear
23+
*.zip
24+
*.tar.gz
25+
*.rar
26+
27+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
28+
hs_err_pid*
29+
replay_pid*
30+
31+
### IntelliJ IDEA ###
32+
.idea/modules.xml
33+
.idea/jarRepositories.xml
34+
.idea/compiler.xml
35+
.idea/libraries/
36+
*.iws
37+
*.iml
38+
*.ipr
39+
40+
### Eclipse ###
41+
.apt_generated
42+
.classpath
43+
.factorypath
44+
.project
45+
.settings
46+
.springBeans
47+
.sts4-cache
48+
49+
### NetBeans ###
50+
/nbproject/private/
51+
/nbbuild/
52+
/dist/
53+
/nbdist/
54+
/.nb-gradle/
55+
build/
56+
!**/src/main/**/build/
57+
!**/src/test/**/build/
58+
59+
### VS Code ###
60+
.vscode/*
61+
!.vscode/settings.json
62+
!.vscode/tasks.json
63+
!.vscode/launch.json
64+
!.vscode/extensions.json
65+
!.vscode/*.code-snippets
66+
.history/
67+
*.vsix
68+
69+
### Mac OS ###
70+
.DS_Store

example_code/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Amazon Bedrock Java Examples
2+
3+
To build and run these AWS SDK for Java (v2) code examples, you need the following:
4+
5+
* [Apache Maven](https://maven.apache.org/) (>3.0)
6+
* [AWS SDK for Java](https://aws.amazon.com/sdk-for-java/) (downloaded and extracted somewhere on
7+
your machine)
8+
* **All Java examples assume that you have set up your credentials in the credentials file in the .aws folder**. For information about how to set AWS credentials and the AWS Region, see [Set up AWS credentials and Region for development](http://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/setup-credentials.html) in the *AWS SDK for Java Developer Guide*.
9+
10+
## Build and run the service examples
11+
12+
### Build the examples using Apache Maven or Gradle
13+
14+
To run these examples, you can setup your development environment to use Apache Maven or Gradle to configure and build AWS SDK for Java projects. For more information, see "Get started with the AWS SDK for Java 2.x" located at https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html.
15+
16+
### Build the examples from the command line
17+
18+
To build any of the service examples, open a command-prompt (terminal) window and change to the directory containing the examples you want to build or run. Then type::
19+
20+
```bash
21+
mvn package
22+
```
23+
24+
### Run the service examples
25+
26+
**IMPORTANT:**
27+
28+
The examples perform AWS operations for the account for which you've specified credentials, and you may incur AWS service charges by running them. See the [AWS Pricing](https://aws.amazon.com/pricing/) page for details about the charges you can expect for a given service and operation.
29+
30+
Some of these examples may perform *destructive* operations on AWS resources, such as deleting an Amazon S3 bucket or an Amazon DynamoDB table. **Be very careful** when running an operation that may delete or modify AWS resources in your account. It's best to create separate test-only resources when experimenting with these examples.
31+
32+
You can run an example using the following command:
33+
34+
```bash
35+
mvn exec:java -Dexec.mainClass="aws.community.examples.[CLASS_NAME]"
36+
```
37+
38+
For example, to run "InvokeBedrock", use this command:
39+
40+
```bash
41+
mvn exec:java -Dexec.mainClass="aws.community.examples.InvokeBedrock"
42+
```

pom.xml renamed to example_code/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,23 @@
99
<version>0.1</version>
1010

1111
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1213
<maven.compiler.source>11</maven.compiler.source>
1314
<maven.compiler.target>11</maven.compiler.target>
1415
</properties>
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.codehaus.mojo</groupId>
20+
<artifactId>exec-maven-plugin</artifactId>
21+
<version>3.1.0</version>
22+
<configuration>
23+
<commandlineArgs>-Dfile.encoding=UTF-16</commandlineArgs>
24+
<cleanupDaemonThreads>false</cleanupDaemonThreads>
25+
</configuration>
26+
</plugin>
27+
</plugins>
28+
</build>
1529

1630
<dependencyManagement>
1731
<dependencies>

src/main/java/aws/community/examples/InvokeBedrock.java renamed to example_code/src/main/java/aws/community/examples/InvokeBedrock.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ public class InvokeBedrock {
1515
public static void main(String[] args) {
1616
BedrockRuntimeClient runtime = BedrockRuntimeClient.builder()
1717
.region(Region.US_EAST_1)
18-
.credentialsProvider(ProfileCredentialsProvider.create())
1918
.build();
2019

21-
String prompt = "Generate a list of names for a fun brand of chili sauce";
20+
String prompt = "Hello Claude, how are you?";
2221

2322
JSONObject jsonBody = new JSONObject()
2423
.put("prompt", "Human: " + prompt + " Assistant:")
@@ -42,7 +41,8 @@ public static void main(String[] args) {
4241

4342
String completion = jsonObject.getString("completion");
4443

45-
System.out.println("-------------------------------------");
44+
System.out.println();
4645
System.out.println(completion);
46+
System.out.println();
4747
}
4848
}

0 commit comments

Comments
 (0)