0
# Service Management
1
2
Comprehensive AWS service support with predefined service constants and custom service definition capabilities for LocalStack container configuration.
3
4
## Capabilities
5
6
### Service Enumeration
7
8
Predefined constants for 23+ AWS services with LocalStack-specific names and legacy port mappings.
9
10
```java { .api }
11
public enum Service implements EnabledService {
12
API_GATEWAY("apigateway", 4567),
13
EC2("ec2", 4597),
14
KINESIS("kinesis", 4568),
15
DYNAMODB("dynamodb", 4569),
16
DYNAMODB_STREAMS("dynamodbstreams", 4570),
17
S3("s3", 4572),
18
FIREHOSE("firehose", 4573),
19
LAMBDA("lambda", 4574),
20
SNS("sns", 4575),
21
SQS("sqs", 4576),
22
REDSHIFT("redshift", 4577),
23
SES("ses", 4579),
24
ROUTE53("route53", 4580),
25
CLOUDFORMATION("cloudformation", 4581),
26
CLOUDWATCH("cloudwatch", 4582),
27
SSM("ssm", 4583),
28
SECRETSMANAGER("secretsmanager", 4584),
29
STEPFUNCTIONS("stepfunctions", 4585),
30
CLOUDWATCHLOGS("logs", 4586),
31
STS("sts", 4592),
32
IAM("iam", 4593),
33
KMS("kms", 4599);
34
}
35
```
36
37
### Service Interface
38
39
Interface for defining enabled LocalStack services, supporting both predefined and custom services.
40
41
```java { .api }
42
public interface EnabledService {
43
/**
44
* Create a custom service by name
45
* @param name LocalStack service name
46
* @return EnabledService instance
47
*/
48
static EnabledService named(String name);
49
50
/**
51
* Get the LocalStack service name
52
* @return service name string used by LocalStack
53
*/
54
String getName();
55
56
/**
57
* Get the service port (defaults to 4566 for modern LocalStack versions)
58
* @return port number for the service
59
*/
60
default int getPort();
61
}
62
```
63
64
### Service Enum Methods
65
66
Methods available on Service enum values for retrieving service information.
67
68
```java { .api }
69
/**
70
* Get the LocalStack service name
71
* @return LocalStack-specific service name
72
*/
73
public String getName();
74
75
/**
76
* Get the service port for legacy mode
77
* @deprecated Since LocalStack 0.11+, all services use single port 4566
78
* @return service-specific port number
79
*/
80
@Deprecated
81
public int getPort();
82
```
83
84
## Service Reference
85
86
### Storage Services
87
88
```java
89
Service.S3 // Amazon Simple Storage Service
90
Service.REDSHIFT // Amazon Redshift
91
```
92
93
### Compute Services
94
95
```java
96
Service.LAMBDA // AWS Lambda
97
Service.EC2 // Amazon Elastic Compute Cloud
98
Service.FIREHOSE // Amazon Kinesis Data Firehose
99
```
100
101
### Database Services
102
103
```java
104
Service.DYNAMODB // Amazon DynamoDB
105
Service.DYNAMODB_STREAMS // DynamoDB Streams
106
```
107
108
### Messaging Services
109
110
```java
111
Service.SQS // Amazon Simple Queue Service
112
Service.SNS // Amazon Simple Notification Service
113
Service.KINESIS // Amazon Kinesis
114
Service.SES // Amazon Simple Email Service
115
```
116
117
### Security & Identity Services
118
119
```java
120
Service.IAM // AWS Identity and Access Management
121
Service.STS // AWS Security Token Service
122
Service.KMS // AWS Key Management Service
123
Service.SECRETSMANAGER // AWS Secrets Manager
124
```
125
126
### Management & Governance Services
127
128
```java
129
Service.CLOUDFORMATION // AWS CloudFormation
130
Service.CLOUDWATCH // Amazon CloudWatch
131
Service.CLOUDWATCHLOGS // Amazon CloudWatch Logs
132
Service.SSM // AWS Systems Manager
133
```
134
135
### Application Integration Services
136
137
```java
138
Service.API_GATEWAY // Amazon API Gateway
139
Service.STEPFUNCTIONS // AWS Step Functions
140
```
141
142
### Networking Services
143
144
```java
145
Service.ROUTE53 // Amazon Route 53
146
```
147
148
## Usage Examples
149
150
### Using Predefined Services
151
152
```java
153
import org.testcontainers.containers.localstack.LocalStackContainer;
154
import org.testcontainers.containers.localstack.LocalStackContainer.Service;
155
156
// Basic web application stack
157
LocalStackContainer localstack = new LocalStackContainer(localstackImage)
158
.withServices(
159
Service.S3, // File storage
160
Service.DYNAMODB, // Database
161
Service.SQS, // Message queue
162
Service.SNS, // Notifications
163
Service.LAMBDA // Serverless functions
164
);
165
166
// Complete AWS development stack
167
LocalStackContainer localstack = new LocalStackContainer(localstackImage)
168
.withServices(
169
Service.S3,
170
Service.LAMBDA,
171
Service.API_GATEWAY,
172
Service.DYNAMODB,
173
Service.DYNAMODB_STREAMS,
174
Service.SQS,
175
Service.SNS,
176
Service.KINESIS,
177
Service.CLOUDFORMATION,
178
Service.CLOUDWATCH,
179
Service.CLOUDWATCHLOGS,
180
Service.IAM,
181
Service.STS,
182
Service.KMS
183
);
184
```
185
186
### Using Custom Services
187
188
```java
189
import org.testcontainers.containers.localstack.LocalStackContainer.EnabledService;
190
191
// Custom services not in the enum
192
LocalStackContainer localstack = new LocalStackContainer(localstackImage)
193
.withServices(
194
EnabledService.named("events"), // EventBridge
195
EnabledService.named("logs"), // CloudWatch Logs
196
EnabledService.named("timestream"), // Amazon Timestream
197
EnabledService.named("appconfig") // AWS AppConfig
198
);
199
```
200
201
### Mixed Configuration
202
203
```java
204
// Combine predefined and custom services
205
LocalStackContainer localstack = new LocalStackContainer(localstackImage)
206
.withServices(
207
Service.S3,
208
Service.LAMBDA,
209
Service.SQS,
210
EnabledService.named("events"),
211
EnabledService.named("scheduler")
212
);
213
```
214
215
### Service Information Access
216
217
```java
218
// Get service names and ports
219
String s3Name = Service.S3.getName(); // Returns "s3"
220
int s3Port = Service.S3.getPort(); // Returns 4572 (legacy)
221
String lambdaName = Service.LAMBDA.getName(); // Returns "lambda"
222
223
// Create custom service and get information
224
EnabledService customService = EnabledService.named("events");
225
String customName = customService.getName(); // Returns "events"
226
int customPort = customService.getPort(); // Returns 4566 (default)
227
```
228
229
### Version Compatibility
230
231
The service configuration behavior adapts based on LocalStack version:
232
233
- **< 0.13.0**: Services list is required, container fails to start without services
234
- **>= 0.13.0**: Services list is optional, containers start lazily
235
- **< 0.11.0**: Each service uses individual ports (legacy mode)
236
- **>= 0.11.0**: All services use single port 4566 (modern mode)
237
238
```java
239
// For modern LocalStack versions, services are optional
240
LocalStackContainer localstack = new LocalStackContainer(
241
DockerImageName.parse("localstack/localstack:3.5.0")
242
);
243
// No .withServices() call needed - services start on demand
244
245
// For older versions, services must be specified
246
LocalStackContainer legacyLocalstack = new LocalStackContainer(
247
DockerImageName.parse("localstack/localstack:0.12.0")
248
)
249
.withServices(Service.S3, Service.LAMBDA);
250
```