Skip to content

fix: disable idempotency doesn't disable dynamodb client creation in persistent store #796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Object around(ProceedingJoinPoint pjp,
Idempotent idempotent) throws Throwable {

String idempotencyDisabledEnv = System.getenv().get(Constants.IDEMPOTENCY_DISABLED_ENV);
if (idempotencyDisabledEnv != null && !idempotencyDisabledEnv.equals("false")) {
if (idempotencyDisabledEnv != null && !idempotencyDisabledEnv.equalsIgnoreCase("false")) {
return pjp.proceed(pjp.getArgs());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,18 @@ private DynamoDBPersistenceStore(String tableName,
if (client != null) {
this.dynamoDbClient = client;
} else {
DynamoDbClientBuilder ddbBuilder = DynamoDbClient.builder()
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.httpClient(UrlConnectionHttpClient.builder().build())
.region(Region.of(System.getenv(AWS_REGION_ENV)));
this.dynamoDbClient = ddbBuilder.build();
String idempotencyDisabledEnv = System.getenv().get(Constants.IDEMPOTENCY_DISABLED_ENV);
if (idempotencyDisabledEnv == null || idempotencyDisabledEnv.equalsIgnoreCase("false")) {
DynamoDbClientBuilder ddbBuilder = DynamoDbClient.builder()
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.httpClient(UrlConnectionHttpClient.builder().build())
.region(Region.of(System.getenv(AWS_REGION_ENV)));
this.dynamoDbClient = ddbBuilder.build();
} else {
// we do not want to create a DynamoDbClient if idempotency is disabled
// null is ok as idempotency won't be called
this.dynamoDbClient = null;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetEnvironmentVariable;
import software.amazon.awssdk.services.dynamodb.model.*;
import software.amazon.lambda.powertools.idempotency.Constants;
import software.amazon.lambda.powertools.idempotency.DynamoDBConfig;
import software.amazon.lambda.powertools.idempotency.IdempotencyConfig;
import software.amazon.lambda.powertools.idempotency.exceptions.IdempotencyItemAlreadyExistsException;
Expand Down Expand Up @@ -260,6 +262,13 @@ public void endToEndWithCustomAttrNamesAndSortKey() throws IdempotencyItemNotFou
}
}

@Test
@SetEnvironmentVariable(key = Constants.IDEMPOTENCY_DISABLED_ENV, value = "true")
public void idempotencyDisabled_noClientShouldBeCreated() {
DynamoDBPersistenceStore store = DynamoDBPersistenceStore.builder().withTableName(TABLE_NAME).build();
assertThatThrownBy(() -> store.getRecord("fake")).isInstanceOf(NullPointerException.class);
}

@BeforeEach
public void setup() {
dynamoDBPersistenceStore = DynamoDBPersistenceStore.builder()
Expand Down