-
Notifications
You must be signed in to change notification settings - Fork 90
feat: Add AppConfig provider to parameters module #1104
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
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
50a0155
Starting AppConfigProvider
scottgerring f3d6e8e
Merge remote-tracking branch 'origin/master' into feat-params-appconfig
scottgerring a273dc3
Fleshing it out
scottgerring 383bff7
Merge branch 'master' into feat-params-appconfig
scottgerring 78ba7be
Adding tests
scottgerring 70db445
Remove cruft
scottgerring 0a5bef1
Advancing the e2e tests and impl
scottgerring 3639a1e
E2E test for params working
scottgerring c71e4e0
More tests + inline doco
scottgerring dce177f
Fix bug and docs
scottgerring fcadb92
More testing
scottgerring 713158c
More test
scottgerring a804069
Remove cruft
scottgerring 5cb36dd
MOre cleanup
scottgerring 5ff3e3e
Update docs/utilities/parameters.md
scottgerring 46a16db
Update powertools-parameters/src/main/java/software/amazon/lambda/pow…
scottgerring 1059274
Merge remote-tracking branch 'origin/master' into feat-params-appconfig
scottgerring 105efce
Fix comment
scottgerring ff701a8
Address field name issue
scottgerring e8a95e9
Use appropriate credentials provider depending on whether or not we'r…
scottgerring e155a66
Merge remote-tracking branch 'refs/remotes/origin/feat-params-appconf…
scottgerring c6eb2c9
Address review feedback
scottgerring d28189b
Merge remote-tracking branch 'origin/master' into feat-params-appconfig
scottgerring 304b413
Merge branch 'master' into feat-params-appconfig
scottgerring 2edb99d
Merge branch 'master' into feat-params-appconfig
scottgerring 3269abe
Merge branch 'main' into feat-params-appconfig
jeromevdl c607af3
Address @kozub feedback
scottgerring 6652c82
Merge remote-tracking branch 'refs/remotes/origin/feat-params-appconf…
scottgerring d03d5de
Remove unecessary captor
scottgerring 9c22306
Merge branch 'main' into feat-params-appconfig
scottgerring File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>e2e-test-handlers-parent</artifactId> | ||
<version>1.0.0</version> | ||
</parent> | ||
|
||
<artifactId>e2e-test-handler-parameters</artifactId> | ||
<packaging>jar</packaging> | ||
<name>A Lambda function using powertools logging</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-logging</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-parameters</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-lambda-java-events</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>aspectj-maven-plugin</artifactId> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<complianceLevel>${maven.compiler.target}</complianceLevel> | ||
<aspectLibraries> | ||
<aspectLibrary> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-logging</artifactId> | ||
</aspectLibrary> | ||
</aspectLibraries> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
22 changes: 22 additions & 0 deletions
22
...sts/handlers/parameters/src/main/java/software/amazon/lambda/powertools/e2e/Function.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package software.amazon.lambda.powertools.e2e; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import software.amazon.lambda.powertools.logging.Logging; | ||
import software.amazon.lambda.powertools.parameters.ParamManager; | ||
import software.amazon.lambda.powertools.parameters.cache.CacheManager; | ||
import software.amazon.lambda.powertools.parameters.AppConfigProvider; | ||
|
||
public class Function implements RequestHandler<Input, String> { | ||
|
||
private static final Logger LOG = LogManager.getLogger(Function.class); | ||
|
||
@Logging | ||
public String handleRequest(Input input, Context context) { | ||
AppConfigProvider provider = ParamManager.getAppConfigProvider(input.getEnvironment(), input.getApp()); | ||
return provider.get(input.getKey()); | ||
|
||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...-tests/handlers/parameters/src/main/java/software/amazon/lambda/powertools/e2e/Input.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package software.amazon.lambda.powertools.e2e; | ||
|
||
import java.util.Map; | ||
|
||
public class Input { | ||
|
||
private String app; | ||
private String environment; | ||
private String key; | ||
|
||
public Input() { | ||
scottgerring marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
} | ||
|
||
public void setApp(String app) { | ||
this.app = app; | ||
} | ||
|
||
public void setEnvironment(String environment) { | ||
this.environment = environment; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public String getApp() { | ||
return app; | ||
} | ||
|
||
public String getEnvironment() { | ||
return environment; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
powertools-e2e-tests/handlers/parameters/src/main/resources/log4j2.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration> | ||
<Appenders> | ||
<Console name="JsonAppender" target="SYSTEM_OUT"> | ||
<JsonTemplateLayout eventTemplateUri="classpath:LambdaJsonLayout.json" /> | ||
</Console> | ||
</Appenders> | ||
<Loggers> | ||
<Root level="INFO"> | ||
<AppenderRef ref="JsonAppender"/> | ||
</Root> | ||
<Logger name="JsonLogger" level="INFO" additivity="false"> | ||
<AppenderRef ref="JsonAppender"/> | ||
</Logger> | ||
</Loggers> | ||
</Configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/ParametersE2ET.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package software.amazon.lambda.powertools; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.*; | ||
import software.amazon.lambda.powertools.testutils.AppConfig; | ||
import software.amazon.lambda.powertools.testutils.Infrastructure; | ||
import software.amazon.lambda.powertools.testutils.lambda.InvocationResult; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static software.amazon.lambda.powertools.testutils.lambda.LambdaInvoker.invokeFunction; | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
public class ParametersE2ET { | ||
|
||
|
||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
private Infrastructure infrastructure; | ||
private String functionName; | ||
private final AppConfig appConfig; | ||
|
||
public ParametersE2ET() { | ||
Map<String,String> params = new HashMap<>(); | ||
params.put("key1", "value1"); | ||
params.put("key2", "value2"); | ||
appConfig = new AppConfig("e2eApp", "e2etest", params); | ||
} | ||
@BeforeAll | ||
@Timeout(value = 5, unit = TimeUnit.MINUTES) | ||
public void setup() { | ||
infrastructure = Infrastructure.builder() | ||
.testName(ParametersE2ET.class.getSimpleName()) | ||
.pathToFunction("parameters") | ||
.appConfig(appConfig) | ||
.environmentVariables( | ||
Stream.of(new String[][]{ | ||
{"POWERTOOLS_LOG_LEVEL", "INFO"}, | ||
{"POWERTOOLS_SERVICE_NAME", ParametersE2ET.class.getSimpleName()} | ||
}) | ||
.collect(Collectors.toMap(data -> data[0], data -> data[1]))) | ||
.build(); | ||
functionName = infrastructure.deploy(); | ||
} | ||
|
||
@AfterAll | ||
public void tearDown() { | ||
if (infrastructure != null) | ||
infrastructure.destroy(); | ||
} | ||
|
||
@Test | ||
public void test_getAppConfigValue() { | ||
for (Map.Entry<String, String >configKey: appConfig.getConfigurationValues().entrySet()) { | ||
|
||
// Arrange | ||
String event1 = "{" + | ||
"\"app\": \"" + appConfig.getApplication() + "\", " + | ||
"\"environment\": \"" + appConfig.getEnvironment() + "\", " + | ||
"\"key\": \"" + configKey.getKey() + "\"" + | ||
"}"; | ||
|
||
// Act | ||
InvocationResult invocationResult = invokeFunction(functionName, event1); | ||
|
||
// Assert | ||
assertThat(invocationResult.getResult()).isEqualTo("\"" + configKey.getValue() + "\""); | ||
} | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...rtools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/AppConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package software.amazon.lambda.powertools.testutils; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Defines configuration used to setup an AppConfig | ||
* deployment when the infrastructure is rolled out. | ||
* | ||
* All fields are non-nullable. | ||
*/ | ||
public class AppConfig { | ||
private String application; | ||
private String environment; | ||
private Map<String, String> configurationValues; | ||
|
||
public AppConfig(String application, String environment, Map<String, String> configurationValues) { | ||
this.application = application; | ||
this.environment = environment; | ||
this.configurationValues = configurationValues; | ||
} | ||
|
||
public String getApplication() { | ||
return application; | ||
} | ||
|
||
public String getEnvironment() { | ||
return environment; | ||
} | ||
|
||
public Map<String, String> getConfigurationValues() { | ||
return configurationValues; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.