Skip to content

Commit 2c58339

Browse files
authored
Add a Quarkus demo
Add a demo using Quarkus.io, based on https://github.com/vsenger/quarkus-bedrock by Vinicius Senger
1 parent 19d4c42 commit 2c58339

File tree

13 files changed

+951
-1
lines changed

13 files changed

+951
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
target/
2+
!**/src/main/**/target/
3+
!**/src/test/**/target/
4+
5+
.aws-sam/*
6+
7+
# Compiled class file
8+
*.class
9+
10+
# Log file
11+
*.log
12+
13+
# BlueJ files
14+
*.ctxt
15+
16+
# Mobile Tools for Java (J2ME)
17+
.mtj.tmp/
18+
19+
# Package Files #
20+
*.jar
21+
*.war
22+
*.nar
23+
*.ear
24+
*.zip
25+
*.tar.gz
26+
*.rar
27+
28+
!.mvn/wrapper/maven-wrapper.jar
29+
30+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
31+
hs_err_pid*
32+
replay_pid*
33+
34+
### IntelliJ IDEA ###
35+
.idea/*
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+
### VS Code ###
50+
.vscode/*
51+
.history/
52+
*.vsix
53+
54+
### Mac OS ###
55+
.DS_Store
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Amazon Bedrock Demo using Quarkus
2+
3+
This is a sample project showing how to access Amazon Bedrock from a Quarkus application deployed on AWS Lambda as a fat jar app.
4+
5+
## Prerequisites
6+
7+
To deploy this demo you need:
8+
- Access to an [AWS account](https://aws.amazon.com/free/)
9+
- [Apache Maven](https://maven.apache.org/)
10+
- [Quarkus](https://quarkus.io/)
11+
- The [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html)
12+
13+
14+
## Build the application
15+
To build the application, execute the following command in the `quarkus-bedrock-demo` directory:
16+
17+
```bash
18+
quarkus build
19+
```
20+
21+
## Deploy the application
22+
To deploy the application, execute the following command in the `quarkus-bedrock-demo` directory:
23+
24+
```bash
25+
sam deploy --guided
26+
```
27+
28+
**Note:** You can accept all default settings, except the following two:
29+
30+
- **AWS Region** must be set a region that supports Bedrock, e.g. **us-east-1**.
31+
- **QuarkusBedrock has no authentication. Is this okay?** must be answered with `[Y]`.
32+
33+
```
34+
Setting default arguments for 'sam deploy'
35+
=========================================
36+
...
37+
AWS Region []: us-east-1
38+
...
39+
QuarkusBedrock has no authentication. Is this okay? [y/N]: Y
40+
...
41+
```
42+
43+
After successful deployment, you will see the generated output:
44+
45+
```
46+
CloudFormation outputs from deployed stack
47+
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
48+
Outputs
49+
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
50+
Key QuarkusBedrock
51+
Description URL for application
52+
Value https://URL_PREFIX.execute-api.us-east-1.amazonaws.com/
53+
----------------------------------------------------------------------------
54+
55+
Successfully created/updated stack - quarkus-bedrock-demo in us-east-1
56+
```
57+
58+
## Access the Application
59+
60+
*Note: Replace `URL_PREFIX.execute-api.us-east-1.amazonaws.com` with the actual URL that has been returned during the deployment.*
61+
62+
### Send a prompt
63+
64+
To send a prompt to the currently active model, use the following endpoint:
65+
66+
```
67+
https://URL_PREFIX.execute-api.us-east-1.amazonaws.com/bedrock/prompt?p=YOUR_PROMPT
68+
```
69+
70+
Example:
71+
72+
```
73+
https://URL_PREFIX.execute-api.us-east-1.amazonaws.com/bedrock/prompt?p=Hello, how are you?
74+
```
75+
76+
### Check active model
77+
78+
To check which model is currently active, use the following endpoint:
79+
80+
```
81+
https://URL_PREFIX.execute-api.us-east-1.amazonaws.com/bedrock/llm
82+
```
83+
84+
### Change active model
85+
86+
To change the active model, use the following endpoint:
87+
88+
```
89+
https://URL_PREFIX.execute-api.us-east-1.amazonaws.com/bedrock/llm/set?model=NEW_MODEL
90+
```
91+
92+
Example:
93+
94+
```
95+
https://URL_PREFIX.execute-api.us-east-1.amazonaws.com/bedrock/llm/set?model=anthropic.claude-instant-v1
96+
```
97+
98+
99+
The following models are currently available as part of this app:
100+
- `anthropic.claude-v1`
101+
- `anthropic.claude-instant-v1`
102+
- `anthropic.claude-v2`
103+
104+
## Environment Cleanup
105+
106+
To delete the SAM application, navigate to the `quarkus-bedrock` directory, execute the following command, and answer "y" to all prompts:
107+
108+
```bash
109+
sam delete
110+
```
111+
112+
113+

demos/quarkus-bedrock-demo/pom.xml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?xml version="1.0"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.acme</groupId>
6+
<artifactId>quarkus-bedrock</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<properties>
9+
<compiler-plugin.version>3.11.0</compiler-plugin.version>
10+
<maven.compiler.release>17</maven.compiler.release>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
13+
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
14+
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
15+
<quarkus.platform.version>3.4.2</quarkus.platform.version>
16+
<skipITs>true</skipITs>
17+
<surefire-plugin.version>3.1.2</surefire-plugin.version>
18+
</properties>
19+
<dependencyManagement>
20+
<dependencies>
21+
<dependency>
22+
<groupId>${quarkus.platform.group-id}</groupId>
23+
<artifactId>${quarkus.platform.artifact-id}</artifactId>
24+
<version>${quarkus.platform.version}</version>
25+
<type>pom</type>
26+
<scope>import</scope>
27+
</dependency>
28+
</dependencies>
29+
</dependencyManagement>
30+
<dependencies>
31+
<dependency>
32+
<groupId>io.quarkus</groupId>
33+
<artifactId>quarkus-arc</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>io.quarkus</groupId>
37+
<artifactId>quarkus-resteasy-reactive</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.quarkus</groupId>
41+
<artifactId>quarkus-amazon-lambda-http</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>io.quarkus</groupId>
45+
<artifactId>quarkus-junit5</artifactId>
46+
<scope>test</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>io.rest-assured</groupId>
50+
<artifactId>rest-assured</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>software.amazon.awssdk</groupId>
55+
<artifactId>bedrockruntime</artifactId>
56+
<version>2.20.162</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>software.amazon.awssdk</groupId>
60+
<artifactId>bedrock</artifactId>
61+
<version>2.20.162</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.json</groupId>
65+
<artifactId>json</artifactId>
66+
<version>20230618</version>
67+
</dependency>
68+
</dependencies>
69+
<build>
70+
<plugins>
71+
<plugin>
72+
<groupId>${quarkus.platform.group-id}</groupId>
73+
<artifactId>quarkus-maven-plugin</artifactId>
74+
<version>${quarkus.platform.version}</version>
75+
<extensions>true</extensions>
76+
<executions>
77+
<execution>
78+
<goals>
79+
<goal>build</goal>
80+
<goal>generate-code</goal>
81+
<goal>generate-code-tests</goal>
82+
</goals>
83+
</execution>
84+
</executions>
85+
</plugin>
86+
<plugin>
87+
<artifactId>maven-compiler-plugin</artifactId>
88+
<version>${compiler-plugin.version}</version>
89+
<configuration>
90+
<compilerArgs>
91+
<arg>-parameters</arg>
92+
</compilerArgs>
93+
</configuration>
94+
</plugin>
95+
<plugin>
96+
<artifactId>maven-surefire-plugin</artifactId>
97+
<version>${surefire-plugin.version}</version>
98+
<configuration>
99+
<systemPropertyVariables>
100+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
101+
<maven.home>${maven.home}</maven.home>
102+
</systemPropertyVariables>
103+
</configuration>
104+
</plugin>
105+
<plugin>
106+
<artifactId>maven-failsafe-plugin</artifactId>
107+
<version>${surefire-plugin.version}</version>
108+
<executions>
109+
<execution>
110+
<goals>
111+
<goal>integration-test</goal>
112+
<goal>verify</goal>
113+
</goals>
114+
<configuration>
115+
<systemPropertyVariables>
116+
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
117+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
118+
<maven.home>${maven.home}</maven.home>
119+
</systemPropertyVariables>
120+
</configuration>
121+
</execution>
122+
</executions>
123+
</plugin>
124+
</plugins>
125+
</build>
126+
<profiles>
127+
<profile>
128+
<id>native</id>
129+
<activation>
130+
<property>
131+
<name>native</name>
132+
</property>
133+
</activation>
134+
<properties>
135+
<skipITs>false</skipITs>
136+
<quarkus.package.type>native</quarkus.package.type>
137+
</properties>
138+
</profile>
139+
</profiles>
140+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version = 0.1
2+
[default.deploy.parameters]
3+
stack_name = "quarkus-bedrock-demo"
4+
resolve_s3 = true
5+
s3_prefix = "quarkus-bedrock-demo"
6+
region = "us-east-1"
7+
capabilities = "CAPABILITY_IAM"
8+
image_repositories = []

0 commit comments

Comments
 (0)