Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 14df569

Browse files
committed
add java docs
1 parent e302640 commit 14df569

File tree

1 file changed

+78
-0
lines changed
  • content/en/user-guide/tools/localstack-sdk/java

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: "Java"
3+
weight: 1
4+
description: Use the LocalStack SDK for Java
5+
---
6+
7+
## Introduction
8+
9+
You can use the LocalStack SDK for Java to develop Java applications that interact with the LocalStack platform and internal developer endpoints.
10+
The SDK extends the REST API, offering an object-oriented interface for easier use.
11+
12+
The LocalStack SDK for Java currently supports these features:
13+
14+
- Save, list, load, and delete Cloud Pods.
15+
- Manage fault configurations for the Chaos API.
16+
17+
{{< callout >}}
18+
This SDK is still in a preview phase, and will be subject to fast and breaking changes.
19+
{{< /callout >}}
20+
21+
## Installation
22+
23+
The best way to use the LocalStack SDK for Java in your project is to consume it from Maven Central.
24+
You can use Maven to import the entire SDK into your project.
25+
26+
```xml
27+
<dependency>
28+
<groupId>cloud.localstack</groupId>
29+
<artifactId>localstack-sdk</artifactId>
30+
<version>0.0.1</version>
31+
</dependency>
32+
```
33+
34+
Similarly, you can copy the following line in the dependencies blog of your `build.gradle(.kts)` file if you are using Gradle as a build tool.
35+
36+
```kotlin
37+
implementation("cloud.localstack:localstack-sdk:0.0.1")
38+
```
39+
40+
## Quick Start
41+
42+
Currently, the LocalStack SDK for Java only supports Chaos and Cloud Pods APIs.
43+
Both these features have a client that can be instantiated from the `cloud.localstack.sdk.chaos` and
44+
`cloud.localstack.sdk.pods` package, respectively.
45+
46+
The clients build requests by using the [builder pattern](https://en.wikipedia.org/wiki/Builder_pattern).
47+
For instance, let us imagine the case in which we want to add a fault rule for S3 on the `us-east-1` region.
48+
You first need to use the `FaultRuleRequest` class to build a fault rule request.
49+
Then, you need to pass such a request object to the `addFaultRules` method of a created `ChaosClient`.
50+
51+
```java
52+
import cloud.localstack.sdk.chaos.ChaosClient;
53+
import cloud.localstack.sdk.chaos.requests.FaultRuleRequest;
54+
55+
var client = new ChaosClient();
56+
var faultRuleRequest = new FaultRuleRequest.Builder().faultRule("s3", "us-east-1").build();
57+
var addedRules = client.addFaultRules(request);
58+
```
59+
60+
As a second example, let us look at the necessary code to save and load a Cloud Pod.
61+
The `PodsClient` exposes two functions, `savePod` and `loadPod`, which expect a `SavePodRequest` and a
62+
`LoadPodRequest`, respectively.
63+
The resulting code is the following:
64+
65+
```java
66+
import cloud.localstack.sdk.pods.PodsClient;
67+
import cloud.localstack.sdk.pods.requests.LoadPodRequest;
68+
import cloud.localstack.sdk.pods.requests.SavePodRequest;
69+
70+
var podsClient = new PodsClient();
71+
// save a cloud pod
72+
var saveRequest = new SavePodRequest.Builder().podName(POD_NAME).build();
73+
podsClient.savePod(saveRequest);
74+
75+
//load a cloud pod
76+
var loadRequest = new LoadPodRequest.Builder().podName(POD_NAME).build();
77+
podsClient.loadPod(loadRequest);
78+
```

0 commit comments

Comments
 (0)