docs
0
# Concurrency and Performance Management
1
2
Comprehensive concurrency control and performance optimization for Lambda functions through reserved concurrency limits and provisioned concurrency configurations to manage scaling behavior and reduce cold start latency.
3
4
## Capabilities
5
6
### Function Concurrency Management
7
8
Controls the maximum number of concurrent executions for a function through reserved concurrency allocation.
9
10
#### Set Function Concurrency
11
12
Sets reserved concurrency for a function, limiting maximum concurrent executions.
13
14
```java { .api }
15
/**
16
* Sets reserved concurrency limit for function to control maximum concurrent executions
17
* @param request Concurrency configuration parameters including function name and limit
18
* @return PutFunctionConcurrencyResult containing concurrency configuration details
19
* @throws ServiceException if service encounters an error
20
* @throws ResourceNotFoundException if function does not exist
21
* @throws InvalidParameterValueException if concurrency value is invalid
22
* @throws ResourceConflictException if function is being updated
23
*/
24
PutFunctionConcurrencyResult putFunctionConcurrency(PutFunctionConcurrencyRequest request);
25
26
public class PutFunctionConcurrencyRequest {
27
/** Function name (required) - name, ARN, or partial ARN */
28
private String functionName;
29
/** Reserved concurrency limit (required) - 0 to throttle, 1+ to reserve */
30
private Integer reservedConcurrencyExecutions;
31
}
32
33
public class PutFunctionConcurrencyResult {
34
/** Reserved concurrency limit */
35
private Integer reservedConcurrencyExecutions;
36
}
37
```
38
39
#### Get Function Concurrency
40
41
Retrieves the current concurrency configuration for a function.
42
43
```java { .api }
44
/**
45
* Retrieves function concurrency configuration
46
* @param request Concurrency retrieval parameters including function name
47
* @return GetFunctionConcurrencyResult containing concurrency settings
48
* @throws ServiceException if service encounters an error
49
* @throws ResourceNotFoundException if function does not exist
50
*/
51
GetFunctionConcurrencyResult getFunctionConcurrency(GetFunctionConcurrencyRequest request);
52
53
public class GetFunctionConcurrencyRequest {
54
/** Function name (required) - name, ARN, or partial ARN */
55
private String functionName;
56
}
57
58
public class GetFunctionConcurrencyResult {
59
/** Reserved concurrency limit */
60
private Integer reservedConcurrencyExecutions;
61
}
62
```
63
64
#### Delete Function Concurrency
65
66
Removes reserved concurrency limit, allowing function to use account's unreserved concurrency pool.
67
68
```java { .api }
69
/**
70
* Removes function concurrency limit, returning to shared concurrency pool
71
* @param request Concurrency removal parameters including function name
72
* @return DeleteFunctionConcurrencyResult indicating successful removal
73
* @throws ServiceException if service encounters an error
74
* @throws ResourceNotFoundException if function does not exist
75
* @throws ResourceConflictException if function is being updated
76
*/
77
DeleteFunctionConcurrencyResult deleteFunctionConcurrency(DeleteFunctionConcurrencyRequest request);
78
79
public class DeleteFunctionConcurrencyRequest {
80
/** Function name (required) - name, ARN, or partial ARN */
81
private String functionName;
82
}
83
84
public class DeleteFunctionConcurrencyResult {
85
// Empty result indicating successful removal
86
}
87
```
88
89
## Provisioned Concurrency Management
90
91
Manages pre-warmed execution environments to reduce cold start latency for function versions and aliases.
92
93
### Set Provisioned Concurrency
94
95
Configures provisioned concurrency for a function version or alias.
96
97
```java { .api }
98
/**
99
* Configures provisioned concurrency for alias or version to reduce cold starts
100
* @param request Provisioned concurrency configuration parameters
101
* @return PutProvisionedConcurrencyConfigResult containing configuration details and status
102
* @throws ServiceException if service encounters an error
103
* @throws ResourceNotFoundException if function, version, or alias does not exist
104
* @throws InvalidParameterValueException if configuration parameters are invalid
105
* @throws ResourceConflictException if configuration is being updated
106
*/
107
PutProvisionedConcurrencyConfigResult putProvisionedConcurrencyConfig(PutProvisionedConcurrencyConfigRequest request);
108
109
public class PutProvisionedConcurrencyConfigRequest {
110
/** Function name (required) - name, ARN, or partial ARN */
111
private String functionName;
112
/** Function version or alias (required) - cannot be $LATEST */
113
private String qualifier;
114
/** Provisioned concurrency amount (required) - minimum pre-warmed instances */
115
private Integer provisionedConcurrencyExecutions;
116
}
117
118
public class PutProvisionedConcurrencyConfigResult {
119
/** Requested provisioned concurrency */
120
private Integer requestedProvisionedConcurrencyExecutions;
121
/** Available provisioned concurrency */
122
private Integer availableProvisionedConcurrencyExecutions;
123
/** Allocated provisioned concurrency */
124
private Integer allocatedProvisionedConcurrencyExecutions;
125
/** Configuration status */
126
private ProvisionedConcurrencyStatus status;
127
/** Status reason */
128
private String statusReason;
129
/** Last modified timestamp */
130
private String lastModified;
131
}
132
133
public enum ProvisionedConcurrencyStatus {
134
IN_PROGRESS,
135
READY,
136
FAILED
137
}
138
```
139
140
### Get Provisioned Concurrency Configuration
141
142
Retrieves provisioned concurrency configuration and status.
143
144
```java { .api }
145
/**
146
* Retrieves provisioned concurrency configuration and current status
147
* @param request Configuration retrieval parameters including function and qualifier
148
* @return GetProvisionedConcurrencyConfigResult containing configuration details
149
* @throws ServiceException if service encounters an error
150
* @throws ResourceNotFoundException if configuration does not exist
151
* @throws ProvisionedConcurrencyConfigNotFoundException if no configuration exists
152
*/
153
GetProvisionedConcurrencyConfigResult getProvisionedConcurrencyConfig(GetProvisionedConcurrencyConfigRequest request);
154
155
public class GetProvisionedConcurrencyConfigRequest {
156
/** Function name (required) - name, ARN, or partial ARN */
157
private String functionName;
158
/** Function version or alias (required) */
159
private String qualifier;
160
}
161
162
public class GetProvisionedConcurrencyConfigResult {
163
/** Requested provisioned concurrency */
164
private Integer requestedProvisionedConcurrencyExecutions;
165
/** Available provisioned concurrency */
166
private Integer availableProvisionedConcurrencyExecutions;
167
/** Allocated provisioned concurrency */
168
private Integer allocatedProvisionedConcurrencyExecutions;
169
/** Configuration status */
170
private ProvisionedConcurrencyStatus status;
171
/** Status reason */
172
private String statusReason;
173
/** Last modified timestamp */
174
private String lastModified;
175
}
176
```
177
178
### Delete Provisioned Concurrency Configuration
179
180
Removes provisioned concurrency configuration for a function version or alias.
181
182
```java { .api }
183
/**
184
* Removes provisioned concurrency configuration
185
* @param request Configuration removal parameters including function and qualifier
186
* @return DeleteProvisionedConcurrencyConfigResult indicating successful removal
187
* @throws ServiceException if service encounters an error
188
* @throws ResourceNotFoundException if configuration does not exist
189
* @throws ResourceConflictException if configuration is being updated
190
*/
191
DeleteProvisionedConcurrencyConfigResult deleteProvisionedConcurrencyConfig(DeleteProvisionedConcurrencyConfigRequest request);
192
193
public class DeleteProvisionedConcurrencyConfigRequest {
194
/** Function name (required) - name, ARN, or partial ARN */
195
private String functionName;
196
/** Function version or alias (required) */
197
private String qualifier;
198
}
199
200
public class DeleteProvisionedConcurrencyConfigResult {
201
// Empty result indicating successful removal
202
}
203
```
204
205
### List Provisioned Concurrency Configurations
206
207
Lists all provisioned concurrency configurations for a function.
208
209
```java { .api }
210
/**
211
* Lists all provisioned concurrency configurations for function
212
* @param request Configuration listing parameters including function name and pagination
213
* @return ListProvisionedConcurrencyConfigsResult containing configuration list
214
* @throws ServiceException if service encounters an error
215
* @throws ResourceNotFoundException if function does not exist
216
*/
217
ListProvisionedConcurrencyConfigsResult listProvisionedConcurrencyConfigs(ListProvisionedConcurrencyConfigsRequest request);
218
219
public class ListProvisionedConcurrencyConfigsRequest {
220
/** Function name (required) - name, ARN, or partial ARN */
221
private String functionName;
222
/** Pagination marker (optional) */
223
private String marker;
224
/** Maximum items to return (optional, range: 1-50) */
225
private Integer maxItems;
226
}
227
228
public class ListProvisionedConcurrencyConfigsResult {
229
/** Provisioned concurrency configurations */
230
private List<ProvisionedConcurrencyConfigListItem> provisionedConcurrencyConfigs;
231
/** Pagination marker for next page */
232
private String nextMarker;
233
}
234
235
public class ProvisionedConcurrencyConfigListItem {
236
/** Function ARN */
237
private String functionArn;
238
/** Requested provisioned concurrency */
239
private Integer requestedProvisionedConcurrencyExecutions;
240
/** Available provisioned concurrency */
241
private Integer availableProvisionedConcurrencyExecutions;
242
/** Allocated provisioned concurrency */
243
private Integer allocatedProvisionedConcurrencyExecutions;
244
/** Configuration status */
245
private ProvisionedConcurrencyStatus status;
246
/** Status reason */
247
private String statusReason;
248
/** Last modified timestamp */
249
private String lastModified;
250
}
251
```
252
253
## Usage Examples
254
255
### Setting Reserved Concurrency
256
257
```java
258
AWSLambda lambdaClient = AWSLambdaClientBuilder.defaultClient();
259
260
// Reserve 100 concurrent executions for critical function
261
PutFunctionConcurrencyRequest request = new PutFunctionConcurrencyRequest()
262
.withFunctionName("critical-processing-function")
263
.withReservedConcurrencyExecutions(100);
264
265
PutFunctionConcurrencyResult result = lambdaClient.putFunctionConcurrency(request);
266
System.out.println("Reserved concurrency: " + result.getReservedConcurrencyExecutions());
267
```
268
269
### Throttling Function Executions
270
271
```java
272
// Set reserved concurrency to 0 to throttle all executions
273
PutFunctionConcurrencyRequest throttleRequest = new PutFunctionConcurrencyRequest()
274
.withFunctionName("maintenance-function")
275
.withReservedConcurrencyExecutions(0);
276
277
lambdaClient.putFunctionConcurrency(throttleRequest);
278
System.out.println("Function throttled - all executions will be rejected");
279
```
280
281
### Configuring Provisioned Concurrency
282
283
```java
284
// Configure provisioned concurrency for production alias
285
PutProvisionedConcurrencyConfigRequest request = new PutProvisionedConcurrencyConfigRequest()
286
.withFunctionName("latency-sensitive-api")
287
.withQualifier("PROD")
288
.withProvisionedConcurrencyExecutions(25);
289
290
PutProvisionedConcurrencyConfigResult result = lambdaClient.putProvisionedConcurrencyConfig(request);
291
System.out.println("Status: " + result.getStatus());
292
System.out.println("Requested: " + result.getRequestedProvisionedConcurrencyExecutions());
293
294
// Wait for provisioned concurrency to be ready
295
while (!ProvisionedConcurrencyStatus.READY.equals(result.getStatus())) {
296
Thread.sleep(5000);
297
298
GetProvisionedConcurrencyConfigRequest statusRequest = new GetProvisionedConcurrencyConfigRequest()
299
.withFunctionName("latency-sensitive-api")
300
.withQualifier("PROD");
301
302
GetProvisionedConcurrencyConfigResult statusResult = lambdaClient.getProvisionedConcurrencyConfig(statusRequest);
303
result.setStatus(statusResult.getStatus());
304
System.out.println("Current status: " + result.getStatus());
305
}
306
```
307
308
### Monitoring Concurrency Usage
309
310
```java
311
// Check current concurrency configuration
312
GetFunctionConcurrencyRequest concurrencyRequest = new GetFunctionConcurrencyRequest()
313
.withFunctionName("my-function");
314
315
try {
316
GetFunctionConcurrencyResult concurrencyResult = lambdaClient.getFunctionConcurrency(concurrencyRequest);
317
System.out.println("Reserved concurrency: " + concurrencyResult.getReservedConcurrencyExecutions());
318
} catch (ResourceNotFoundException e) {
319
System.out.println("No reserved concurrency configured - using unreserved pool");
320
}
321
322
// List all provisioned concurrency configurations
323
ListProvisionedConcurrencyConfigsRequest listRequest = new ListProvisionedConcurrencyConfigsRequest()
324
.withFunctionName("my-function");
325
326
ListProvisionedConcurrencyConfigsResult listResult = lambdaClient.listProvisionedConcurrencyConfigs(listRequest);
327
for (ProvisionedConcurrencyConfigListItem config : listResult.getProvisionedConcurrencyConfigs()) {
328
System.out.println("Qualifier: " + extractQualifier(config.getFunctionArn()));
329
System.out.println("Available: " + config.getAvailableProvisionedConcurrencyExecutions() +
330
"/" + config.getRequestedProvisionedConcurrencyExecutions());
331
System.out.println("Status: " + config.getStatus());
332
}
333
```
334
335
### Scaling Strategy Implementation
336
337
```java
338
public class ConcurrencyManager {
339
private final AWSLambda lambdaClient;
340
341
public ConcurrencyManager(AWSLambda lambdaClient) {
342
this.lambdaClient = lambdaClient;
343
}
344
345
/**
346
* Implement blue-green deployment with provisioned concurrency
347
*/
348
public void deployWithProvisionedConcurrency(String functionName, String newVersion) {
349
// Configure provisioned concurrency for new version
350
PutProvisionedConcurrencyConfigRequest newVersionConfig =
351
new PutProvisionedConcurrencyConfigRequest()
352
.withFunctionName(functionName)
353
.withQualifier(newVersion)
354
.withProvisionedConcurrencyExecutions(50);
355
356
lambdaClient.putProvisionedConcurrencyConfig(newVersionConfig);
357
358
// Wait for provisioned concurrency to be ready
359
waitForProvisionedConcurrencyReady(functionName, newVersion);
360
361
// Update alias to point to new version (traffic shift)
362
UpdateAliasRequest aliasUpdate = new UpdateAliasRequest()
363
.withFunctionName(functionName)
364
.withName("PROD")
365
.withFunctionVersion(newVersion);
366
367
lambdaClient.updateAlias(aliasUpdate);
368
369
// Clean up old version's provisioned concurrency after successful deployment
370
// (implementation depends on your retention policy)
371
}
372
373
private void waitForProvisionedConcurrencyReady(String functionName, String qualifier) {
374
GetProvisionedConcurrencyConfigRequest request =
375
new GetProvisionedConcurrencyConfigRequest()
376
.withFunctionName(functionName)
377
.withQualifier(qualifier);
378
379
while (true) {
380
try {
381
GetProvisionedConcurrencyConfigResult result = lambdaClient.getProvisionedConcurrencyConfig(request);
382
if (ProvisionedConcurrencyStatus.READY.equals(result.getStatus())) {
383
break;
384
} else if (ProvisionedConcurrencyStatus.FAILED.equals(result.getStatus())) {
385
throw new RuntimeException("Provisioned concurrency failed: " + result.getStatusReason());
386
}
387
Thread.sleep(5000);
388
} catch (InterruptedException e) {
389
Thread.currentThread().interrupt();
390
throw new RuntimeException("Interrupted while waiting", e);
391
}
392
}
393
}
394
}
395
```
396
397
## Exception Handling
398
399
Common exceptions when managing concurrency:
400
401
- **ResourceNotFoundException**: Function, version, or alias does not exist
402
- **ResourceConflictException**: Function is being updated or configuration conflict
403
- **InvalidParameterValueException**: Invalid concurrency values or qualifier
404
- **ProvisionedConcurrencyConfigNotFoundException**: No provisioned concurrency configuration exists
405
- **ServiceException**: General service errors
406
- **TooManyRequestsException**: Rate limiting exceeded
407
408
## Best Practices
409
410
### Reserved Concurrency
411
- Monitor account-level concurrent execution limits
412
- Reserve concurrency for critical functions to ensure availability
413
- Use throttling (concurrency = 0) for maintenance or emergency stops
414
- Consider regional limits when setting reserved concurrency
415
416
### Provisioned Concurrency
417
- Use for latency-sensitive applications with predictable traffic
418
- Configure provisioned concurrency on stable versions/aliases, not $LATEST
419
- Monitor utilization to optimize provisioned concurrency levels
420
- Consider cost implications - provisioned concurrency incurs charges even when idle
421
422
### Performance Optimization
423
- Combine reserved and provisioned concurrency for critical workloads
424
- Use CloudWatch metrics to monitor concurrency usage and cold starts
425
- Implement gradual scaling during traffic spikes
426
- Test performance impact of concurrency configurations
427
428
### Cost Management
429
- Right-size provisioned concurrency based on actual usage patterns
430
- Use Auto Scaling or custom logic to adjust provisioned concurrency dynamically
431
- Monitor costs and utilization through CloudWatch and billing reports
432
- Clean up unused provisioned concurrency configurations