Skip to content

Commit babe336

Browse files
committed
update DDB client to a 3 retry max to avoid lambda timeout + update to auth token
1 parent eb9d90f commit babe336

File tree

7 files changed

+33
-4
lines changed

7 files changed

+33
-4
lines changed

FIS-experiments/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ cd lambda-functions && mvn clean package shade:shade
3434
### Starting LocalStack
3535

3636
```bash
37-
export LOCALSTACK_API_KEY = <your_localstack_api_key>
37+
export LOCALSTACK_AUTH_TOKEN = <your_localstack_auth_token>
3838
docker compose up
3939
```
4040

FIS-experiments/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
- LOCALSTACK_HOST=localstack # where services are available from other containers
1818
- ENFORCE_IAM=0 # enforce IAM policies
1919
- LAMBDA_DOCKER_NETWORK=ls_network
20-
- LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY}
20+
- LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN}
2121
- LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT=60
2222
- PERSIST_ALL=false
2323

FIS-experiments/lambda-functions/src/main/java/lambda/ProductApi.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import java.net.URI;
5+
56
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
67
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
8+
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
9+
import software.amazon.awssdk.core.retry.RetryPolicy;
710
import software.amazon.awssdk.regions.Region;
811
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
912
import software.amazon.awssdk.services.sns.SnsClient;
@@ -15,6 +18,17 @@ public class ProductApi {
1518
protected static final String topicArn = "arn:aws:sns:us-east-1:000000000000:ProductEventsTopic";
1619
protected ObjectMapper objectMapper = new ObjectMapper();
1720

21+
// Define a custom retry policy
22+
// Set maximum number of retries
23+
RetryPolicy customRetryPolicy = RetryPolicy.builder()
24+
.numRetries(3)
25+
.build();
26+
27+
// Apply the custom retry policy to ClientOverrideConfiguration
28+
ClientOverrideConfiguration clientOverrideConfig = ClientOverrideConfiguration.builder()
29+
.retryPolicy(customRetryPolicy)
30+
.build();
31+
1832
protected SnsClient snsClient = SnsClient.builder()
1933
.endpointOverride(URI.create(String.format("http://%s:4566", LOCALSTACK_HOSTNAME)))
2034
.credentialsProvider(
@@ -28,5 +42,6 @@ public class ProductApi {
2842
StaticCredentialsProvider.create(AwsBasicCredentials.create("test", "test")))
2943
.region(Region.of(AWS_REGION))
3044
.endpointDiscoveryEnabled(true)
45+
.overrideConfiguration(clientOverrideConfig)
3146
.build();
3247
}
363 Bytes
Binary file not shown.

extension-outages/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
- LOCALSTACK_HOST=localstack # where services are available from other containers
1616
- LAMBDA_DOCKER_NETWORK=ls_network
1717
- DISABLE_CUSTOM_CORS_APIGATEWAY=1
18-
- LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY}
18+
- LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN}
1919
- EXTENSION_AUTO_INSTALL=localstack-extension-outages
2020
- LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT=60
2121
- PERSIST_ALL=false

route53-failover/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
- LOCALSTACK_HOST=localstack # where services are available from other containers
1818
- ENFORCE_IAM=0 # enforce IAM policies
1919
- LAMBDA_DOCKER_NETWORK=ls_network
20-
- LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY}
20+
- LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN}
2121
- LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT=60
2222
- DNS_ADDRESS=127.0.0.1
2323
# - EXTENSION_AUTO_INSTALL=localstack-extension-outages

route53-failover/lambda-functions/src/main/java/lambda/ProductApi.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.net.URI;
55
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
66
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
7+
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
8+
import software.amazon.awssdk.core.retry.RetryPolicy;
79
import software.amazon.awssdk.regions.Region;
810
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
911
import software.amazon.awssdk.services.sns.SnsClient;
@@ -15,6 +17,17 @@ public class ProductApi {
1517
protected static final String topicArn = "arn:aws:sns:us-east-1:000000000000:ProductEventsTopic";
1618
protected ObjectMapper objectMapper = new ObjectMapper();
1719

20+
// Define a custom retry policy
21+
// Set maximum number of retries
22+
RetryPolicy customRetryPolicy = RetryPolicy.builder()
23+
.numRetries(3)
24+
.build();
25+
26+
// Apply the custom retry policy to ClientOverrideConfiguration
27+
ClientOverrideConfiguration clientOverrideConfig = ClientOverrideConfiguration.builder()
28+
.retryPolicy(customRetryPolicy)
29+
.build();
30+
1831
protected SnsClient snsClient = SnsClient.builder()
1932
.endpointOverride(URI.create(String.format("http://%s:4566", LOCALSTACK_HOSTNAME)))
2033
.credentialsProvider(
@@ -28,5 +41,6 @@ public class ProductApi {
2841
StaticCredentialsProvider.create(AwsBasicCredentials.create("test", "test")))
2942
.region(Region.of(AWS_REGION))
3043
.endpointDiscoveryEnabled(true)
44+
.overrideConfiguration(clientOverrideConfig)
3145
.build();
3246
}

0 commit comments

Comments
 (0)