generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 101
feat(idempotency): Add functional Idempotency API
#2244
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 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
efeb0ff
Decouple AspectJ dependencies on pjp from IdempotencyHandler.
phipag 6623d89
Create PowertoolsIdempotency functional API with overloads for all us…
phipag 0414e69
Make IdempotencyConfig thread-safe to avoid Lamdba context leaks in c…
phipag 8c56573
Merge branch 'main' into phipag/issue2213
phipag 3383cd2
Fix bug: We need to pass the return type explicitly to support deseri…
phipag f100f49
Address some pmd findings.
phipag c73b3d2
Make java doc consistent in PowertoolsIdempotency.
phipag 9b4fe65
Hide checked exceptions (from AspectJ) from user-facing API in Powert…
phipag bd8e3cd
Remove unncessary try catch Throwable in unit tests
phipag 776c23e
Add E2E test for functional idempotency API.
phipag 06eeebc
Fix sonar issues.
phipag 4dc0790
Remove unncessary constructors for Input object.
phipag 34d73e7
Add support for generic types.
phipag 26ce8f0
Merge PowertoolsIdempotency with Idempotency to offer a single entryp…
phipag 6d3995d
Make ConfigHolder final.
phipag 08eb50c
Make ConfigHolder modifier order comply with java language spec.
phipag e126401
Make Holder class final.
phipag 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
60 changes: 60 additions & 0 deletions
60
powertools-e2e-tests/handlers/idempotency-functional/pom.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,60 @@ | ||
| <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>2.5.0</version> | ||
| </parent> | ||
|
|
||
| <artifactId>e2e-test-handler-idempotency-functional</artifactId> | ||
| <packaging>jar</packaging> | ||
| <name>E2E test handler – Idempotency Functional</name> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>software.amazon.lambda</groupId> | ||
| <artifactId>powertools-idempotency-dynamodb</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>software.amazon.lambda</groupId> | ||
| <artifactId>powertools-logging-log4j</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.amazonaws</groupId> | ||
| <artifactId>aws-lambda-java-events</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.amazonaws</groupId> | ||
| <artifactId>aws-lambda-java-runtime-interface-client</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.amazonaws</groupId> | ||
| <artifactId>aws-lambda-java-core</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-shade-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| <profiles> | ||
| <profile> | ||
| <id>native-image</id> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.graalvm.buildtools</groupId> | ||
| <artifactId>native-maven-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </profile> | ||
| </profiles> | ||
| </project> |
67 changes: 67 additions & 0 deletions
67
.../idempotency-functional/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,67 @@ | ||
| /* | ||
| * Copyright 2023 Amazon.com, Inc. or its affiliates. | ||
| * Licensed under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package software.amazon.lambda.powertools.e2e; | ||
|
|
||
| import java.time.Duration; | ||
| import java.time.Instant; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.time.temporal.ChronoUnit; | ||
| import java.util.TimeZone; | ||
|
|
||
| import com.amazonaws.services.lambda.runtime.Context; | ||
| import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
|
|
||
| import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient; | ||
| import software.amazon.awssdk.regions.Region; | ||
| import software.amazon.awssdk.services.dynamodb.DynamoDbClient; | ||
| import software.amazon.lambda.powertools.idempotency.Idempotency; | ||
| import software.amazon.lambda.powertools.idempotency.IdempotencyConfig; | ||
| import software.amazon.lambda.powertools.idempotency.PowertoolsIdempotency; | ||
| import software.amazon.lambda.powertools.idempotency.persistence.dynamodb.DynamoDBPersistenceStore; | ||
|
|
||
| public class Function implements RequestHandler<Input, String> { | ||
|
|
||
| public Function() { | ||
| this(DynamoDbClient | ||
| .builder() | ||
| .httpClient(UrlConnectionHttpClient.builder().build()) | ||
| .region(Region.of(System.getenv("AWS_REGION"))) | ||
| .build()); | ||
| } | ||
|
|
||
| public Function(DynamoDbClient client) { | ||
| Idempotency.config().withConfig( | ||
| IdempotencyConfig.builder() | ||
| .withExpiration(Duration.of(10, ChronoUnit.SECONDS)) | ||
| .build()) | ||
| .withPersistenceStore( | ||
| DynamoDBPersistenceStore.builder() | ||
| .withDynamoDbClient(client) | ||
| .withTableName(System.getenv("IDEMPOTENCY_TABLE")) | ||
| .build()) | ||
| .configure(); | ||
| } | ||
|
|
||
| public String handleRequest(Input input, Context context) { | ||
| Idempotency.registerLambdaContext(context); | ||
|
|
||
| return PowertoolsIdempotency.makeIdempotent(this::processRequest, input, String.class); | ||
| } | ||
|
|
||
| private String processRequest(Input input) { | ||
|
Check failure on line 63 in powertools-e2e-tests/handlers/idempotency-functional/src/main/java/software/amazon/lambda/powertools/e2e/Function.java
|
||
| DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE_TIME.withZone(TimeZone.getTimeZone("UTC").toZoneId()); | ||
| return dtf.format(Instant.now()); | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
...ers/idempotency-functional/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,27 @@ | ||
| /* | ||
| * Copyright 2023 Amazon.com, Inc. or its affiliates. | ||
| * Licensed under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package software.amazon.lambda.powertools.e2e; | ||
|
|
||
| public class Input { | ||
| private String message; | ||
|
|
||
| public String getMessage() { | ||
| return message; | ||
| } | ||
|
|
||
| public void setMessage(String message) { | ||
| this.message = message; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...in/resources/META-INF/native-image/com.amazonaws/aws-lambda-java-core/reflect-config.json
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,13 @@ | ||
| [ | ||
| { | ||
| "name":"com.amazonaws.services.lambda.runtime.LambdaRuntime", | ||
| "methods":[{"name":"<init>","parameterTypes":[] }], | ||
| "fields":[{"name":"logger"}], | ||
| "allPublicMethods":true | ||
| }, | ||
| { | ||
| "name":"com.amazonaws.services.lambda.runtime.LambdaRuntimeInternal", | ||
| "methods":[{"name":"<init>","parameterTypes":[] }], | ||
| "allPublicMethods":true | ||
| } | ||
| ] |
35 changes: 35 additions & 0 deletions
35
.../resources/META-INF/native-image/com.amazonaws/aws-lambda-java-events/reflect-config.json
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,35 @@ | ||
| [ | ||
| { | ||
| "name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent", | ||
| "allDeclaredFields": true, | ||
| "allDeclaredMethods": true, | ||
| "allDeclaredConstructors": true | ||
| }, | ||
| { | ||
| "name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent$ProxyRequestContext", | ||
| "allDeclaredFields": true, | ||
| "allDeclaredMethods": true, | ||
| "allDeclaredConstructors": true | ||
| }, | ||
| { | ||
| "name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent$RequestIdentity", | ||
| "allDeclaredFields": true, | ||
| "allDeclaredMethods": true, | ||
| "allDeclaredConstructors": true | ||
| }, | ||
| { | ||
| "name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent", | ||
| "allDeclaredFields": true, | ||
| "allDeclaredMethods": true, | ||
| "allDeclaredConstructors": true | ||
| }, | ||
| { | ||
| "name": "com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent", | ||
| "allDeclaredConstructors": true, | ||
| "allPublicConstructors": true, | ||
| "allDeclaredMethods": true, | ||
| "allPublicMethods": true, | ||
| "allDeclaredClasses": true, | ||
| "allPublicClasses": true | ||
| } | ||
| ] |
11 changes: 11 additions & 0 deletions
11
...A-INF/native-image/com.amazonaws/aws-lambda-java-runtime-interface-client/jni-config.json
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,11 @@ | ||
| [ | ||
| { | ||
| "name":"com.amazonaws.services.lambda.runtime.api.client.runtimeapi.LambdaRuntimeClientException", | ||
| "methods":[{"name":"<init>","parameterTypes":["java.lang.String","int"] }] | ||
| }, | ||
| { | ||
| "name":"com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.InvocationRequest", | ||
| "fields":[{"name":"id"}, {"name":"invokedFunctionArn"}, {"name":"deadlineTimeInMs"}, {"name":"xrayTraceId"}, {"name":"clientContext"}, {"name":"cognitoIdentity"}, {"name": "tenantId"}, {"name":"content"}], | ||
| "allPublicMethods":true | ||
| } | ||
| ] |
1 change: 1 addition & 0 deletions
1
...tive-image/com.amazonaws/aws-lambda-java-runtime-interface-client/native-image.properties
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 @@ | ||
| Args = --initialize-at-build-time=jdk.xml.internal.SecuritySupport |
61 changes: 61 additions & 0 deletions
61
...F/native-image/com.amazonaws/aws-lambda-java-runtime-interface-client/reflect-config.json
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 @@ | ||
| [ | ||
| { | ||
| "name": "com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.deser.Deserializers[]" | ||
| }, | ||
| { | ||
| "name": "com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.ext.Java7SupportImpl", | ||
| "methods": [{ "name": "<init>", "parameterTypes": [] }] | ||
| }, | ||
| { | ||
| "name": "com.amazonaws.services.lambda.runtime.LambdaRuntime", | ||
| "fields": [{ "name": "logger" }] | ||
| }, | ||
| { | ||
| "name": "com.amazonaws.services.lambda.runtime.logging.LogLevel", | ||
| "allDeclaredConstructors": true, | ||
| "allPublicConstructors": true, | ||
| "allDeclaredMethods": true, | ||
| "allPublicMethods": true, | ||
| "allDeclaredFields": true, | ||
| "allPublicFields": true | ||
| }, | ||
| { | ||
| "name": "com.amazonaws.services.lambda.runtime.logging.LogFormat", | ||
| "allDeclaredConstructors": true, | ||
| "allPublicConstructors": true, | ||
| "allDeclaredMethods": true, | ||
| "allPublicMethods": true, | ||
| "allDeclaredFields": true, | ||
| "allPublicFields": true | ||
| }, | ||
| { | ||
| "name": "java.lang.Void", | ||
| "methods": [{ "name": "<init>", "parameterTypes": [] }] | ||
| }, | ||
| { | ||
| "name": "java.util.Collections$UnmodifiableMap", | ||
| "fields": [{ "name": "m" }] | ||
| }, | ||
| { | ||
| "name": "jdk.internal.module.IllegalAccessLogger", | ||
| "fields": [{ "name": "logger" }] | ||
| }, | ||
| { | ||
| "name": "sun.misc.Unsafe", | ||
| "fields": [{ "name": "theUnsafe" }] | ||
| }, | ||
| { | ||
| "name": "com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.InvocationRequest", | ||
| "fields": [ | ||
| { "name": "id" }, | ||
| { "name": "invokedFunctionArn" }, | ||
| { "name": "deadlineTimeInMs" }, | ||
| { "name": "xrayTraceId" }, | ||
| { "name": "clientContext" }, | ||
| { "name": "cognitoIdentity" }, | ||
| { "name": "tenantId" }, | ||
| { "name": "content" } | ||
| ], | ||
| "allPublicMethods": true | ||
| } | ||
| ] |
19 changes: 19 additions & 0 deletions
19
.../native-image/com.amazonaws/aws-lambda-java-runtime-interface-client/resource-config.json
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,19 @@ | ||
| { | ||
| "resources": { | ||
| "includes": [ | ||
| { | ||
| "pattern": "\\Qjni/libaws-lambda-jni.linux-aarch_64.so\\E" | ||
| }, | ||
| { | ||
| "pattern": "\\Qjni/libaws-lambda-jni.linux-x86_64.so\\E" | ||
| }, | ||
| { | ||
| "pattern": "\\Qjni/libaws-lambda-jni.linux_musl-aarch_64.so\\E" | ||
| }, | ||
| { | ||
| "pattern": "\\Qjni/libaws-lambda-jni.linux_musl-x86_64.so\\E" | ||
| } | ||
| ] | ||
| }, | ||
| "bundles": [] | ||
| } |
25 changes: 25 additions & 0 deletions
25
...ces/META-INF/native-image/com.amazonaws/aws-lambda-java-serialization/reflect-config.json
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,25 @@ | ||
| [ | ||
| { | ||
| "name": "com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.deser.Deserializers[]" | ||
| }, | ||
| { | ||
| "name": "com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.ext.Java7HandlersImpl", | ||
| "methods": [{ "name": "<init>", "parameterTypes": [] }] | ||
| }, | ||
| { | ||
| "name": "com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.ext.Java7SupportImpl", | ||
| "methods": [{ "name": "<init>", "parameterTypes": [] }] | ||
| }, | ||
| { | ||
| "name": "com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.ser.Serializers[]" | ||
| }, | ||
| { | ||
| "name": "org.joda.time.DateTime", | ||
| "allDeclaredConstructors": true, | ||
| "allPublicConstructors": true, | ||
| "allDeclaredMethods": true, | ||
| "allPublicMethods": true, | ||
| "allDeclaredClasses": true, | ||
| "allPublicClasses": true | ||
| } | ||
| ] |
20 changes: 20 additions & 0 deletions
20
...resources/META-INF/native-image/software.amazon.lambda.powertools.e2e/reflect-config.json
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,20 @@ | ||
| [ | ||
| { | ||
| "name": "software.amazon.lambda.powertools.e2e.Function", | ||
| "allDeclaredConstructors": true, | ||
| "allPublicConstructors": true, | ||
| "allDeclaredMethods": true, | ||
| "allPublicMethods": true, | ||
| "allDeclaredClasses": true, | ||
| "allPublicClasses": true | ||
| }, | ||
| { | ||
| "name": "software.amazon.lambda.powertools.e2e.Input", | ||
| "allDeclaredConstructors": true, | ||
| "allPublicConstructors": true, | ||
| "allDeclaredMethods": true, | ||
| "allPublicMethods": true, | ||
| "allDeclaredClasses": true, | ||
| "allPublicClasses": true | ||
| } | ||
| ] |
7 changes: 7 additions & 0 deletions
7
...esources/META-INF/native-image/software.amazon.lambda.powertools.e2e/resource-config.json
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,7 @@ | ||
| { | ||
| "resources":{ | ||
| "includes":[{ | ||
| "pattern":"\\Qlog4j2.xml\\E" | ||
| }]}, | ||
| "bundles":[] | ||
| } |
16 changes: 16 additions & 0 deletions
16
powertools-e2e-tests/handlers/idempotency-functional/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
Oops, something went wrong.
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.