Skip to content

Commit 198b9ba

Browse files
committed
Removing env var credentials provider.
SnapStart uses a different credentials provider so when it is hardcoded like this, the default will fail.
1 parent 295ee62 commit 198b9ba

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ public class Constants {
1717
public static final String LAMBDA_FUNCTION_NAME_ENV = "AWS_LAMBDA_FUNCTION_NAME";
1818
public static final String AWS_REGION_ENV = "AWS_REGION";
1919
public static final String IDEMPOTENCY_DISABLED_ENV = "POWERTOOLS_IDEMPOTENCY_DISABLED";
20+
public static final String AWS_LAMBDA_INITIALIZATION_TYPE = "AWS_LAMBDA_INITIALIZATION_TYPE";
2021
}

powertools-idempotency/src/main/java/software/amazon/lambda/powertools/idempotency/persistence/DynamoDBPersistenceStore.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ private DynamoDBPersistenceStore(String tableName,
8888
DynamoDbClientBuilder ddbBuilder = DynamoDbClient.builder()
8989
.httpClient(UrlConnectionHttpClient.builder().build())
9090
.region(Region.of(System.getenv(AWS_REGION_ENV)));
91+
92+
// AWS_LAMBDA_INITIALIZATION_TYPE has two values on-demand and snap-start
93+
// when using snap-start mode, the env var creds provider isn't used and causes a fatal error
94+
// fall back to the default provider chain if the mode is anything other than on-demand.
95+
if (System.getenv().get(Constants.AWS_LAMBDA_INITIALIZATION_TYPE) == "on-demand") {
96+
ddbBuilder.credentialsProvider(EnvironmentVariableCredentialsProvider.create());
97+
}
98+
9199
this.dynamoDbClient = ddbBuilder.build();
92100
} else {
93101
// we do not want to create a DynamoDbClient if idempotency is disabled

0 commit comments

Comments
 (0)