Skip to content
Open
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
22 changes: 22 additions & 0 deletions powertools-parameters/powertools-parameters-ssm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<artifactId>aspectjrt</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.crac</groupId>
<artifactId>crac</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down Expand Up @@ -108,6 +112,24 @@
</build>

<profiles>
<profile>
<id>generate-classesloaded-file</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
-Xlog:class+load=info:classesloaded.txt
--add-opens java.base/java.util=ALL-UNNAMED
--add-opens java.base/java.lang=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>native</id>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

import java.util.HashMap;
import java.util.Map;
import org.crac.Core;
import org.crac.Resource;
import software.amazon.awssdk.services.ssm.SsmClient;
import software.amazon.awssdk.services.ssm.model.GetParameterRequest;
import software.amazon.awssdk.services.ssm.model.GetParametersByPathRequest;
import software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse;
import software.amazon.awssdk.utils.StringUtils;
import software.amazon.lambda.powertools.common.internal.ClassPreLoader;
import software.amazon.lambda.powertools.parameters.BaseProvider;
import software.amazon.lambda.powertools.parameters.cache.CacheManager;
import software.amazon.lambda.powertools.parameters.transform.TransformationManager;
Expand Down Expand Up @@ -63,12 +66,25 @@
* >>> /path/to/parameters/others/key3 -> value3
* </pre>
*/
public class SSMProvider extends BaseProvider {
public class SSMProvider extends BaseProvider implements Resource {

private final SsmClient client;
private final ThreadLocal<Boolean> decrypt = ThreadLocal.withInitial(() -> false);
private final ThreadLocal<Boolean> recursive = ThreadLocal.withInitial(() -> false);

// Dummy instance to register SSMProvider with CRaC
private static final SSMProvider INSTANCE =
new SSMProvider(new CacheManager(), new TransformationManager(), null);

// Static block to ensure CRaC registration happens at class loading time
static {
registerWithGlobalContext();
}

static void registerWithGlobalContext() {
Core.getGlobalContext().register(INSTANCE);
}

/**
* Constructor with custom {@link SsmClient}. <br/>
* Use when you need to customize region or any other attribute of the client.<br/><br/>
Expand Down Expand Up @@ -205,4 +221,14 @@ SsmClient getClient() {
return client;
}

@Override
public void beforeCheckpoint(org.crac.Context<? extends Resource> context) throws Exception {
ClassPreLoader.preloadClasses();
}

@Override
public void afterRestore(org.crac.Context<? extends Resource> context) throws Exception {
// No action needed after restore
}

}
Loading