Skip to content

Commit 298a910

Browse files
committed
[1.0.0-SNAPSHOT]
Simplelambda examples updated README.md updated
1 parent e00bdab commit 298a910

File tree

28 files changed

+221
-252
lines changed

28 files changed

+221
-252
lines changed

quarkus-dynamodb/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Quarkus Lambda
22

3-
Template for Quarkus.
3+
Example for Quarkus.
44

55
## Features
66
- Micronaut Plugin for BOM and version management.

quarkus-helloworld/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Quarkus Lambda
22

3-
Template for Quarkus.
3+
Example for Quarkus.
44

55
## Features
66
- Micronaut Plugin for BOM and version management.

quarkus-http/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Quarkus Lambda
22

3-
Template for Quarkus.
3+
Example for Quarkus.
44

55
## Features
66
- Micronaut Plugin for BOM and version management.

simplelambda-auroradb/README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## Simple Lambda
22

3-
Java 17+ AWS Lambda Template with Micronaut DI support with GraalVM native compatibility.
3+
Java 17+ AWS Lambda Example with Micronaut DI support with GraalVM native compatibility.
44

55
## Runtime
66

7-
Template uses [Simple Lambda](https://github.com/GoodforGod/simple-awslambda) with GraalVM native compatibility.
7+
Example uses [Simple Lambda](https://github.com/GoodforGod/simple-awslambda) with GraalVM native compatibility.
88

99
## Deploy
1010

@@ -26,4 +26,14 @@ docker run --rm --entrypoint cat simplelambda-auroradb /home/application/functio
2626

2727
```shell
2828
sam local start-api -t sam.yaml -p 3000
29-
```
29+
```
30+
31+
## Event Example
32+
33+
Example of event to send to lambda:
34+
```json
35+
{
36+
"name": "Steeven King"
37+
}
38+
```
39+

simplelambda-auroradb/src/main/java/io/goodforgod/simplelambda/LambdaEntrypoint.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @since 16.09.2021
1414
*/
1515
@NativeImageHint(entrypoint = LambdaEntrypoint.class,
16+
name = "application",
1617
options = { NativeImageOptions.ALLOW_INCOMPLETE_CLASSPATH, NativeImageOptions.REPORT_UNSUPPORTED })
1718
@InitializationHint(typeNames = {
1819
"io.goodforgod.simplelambda",
@@ -28,7 +29,7 @@
2829
"org.mariadb.jdbc.internal.com.send.authentication.SendPamAuthPacket",
2930
})
3031
@ReflectionHint(types = { Driver.class, DriverManager.class, Options.class })
31-
@ResourceHint(patterns = {
32+
@ResourceHint(include = {
3233
"META-INF/services/java.sql.Driver",
3334
"META-INF/services/org.mariadb.jdbc.authentication.AuthenticationPlugin",
3435
"META-INF/services/org.mariadb.jdbc.credential.CredentialPlugin",

simplelambda-auroradb/src/main/java/io/goodforgod/simplelambda/LambdaHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.amazonaws.services.lambda.runtime.Context;
44
import com.amazonaws.services.lambda.runtime.RequestHandler;
5-
import io.goodforgod.aws.lambda.simple.error.LambdaException;
65
import java.sql.Connection;
76
import java.sql.DriverManager;
87
import java.sql.PreparedStatement;
@@ -53,7 +52,7 @@ public Response handleRequest(Request request, Context context) {
5352
logger.info("Statement executed..");
5453
}
5554
} catch (Exception e) {
56-
throw new LambdaException(e.getMessage());
55+
throw new IllegalStateException(e.getMessage());
5756
}
5857

5958
return new Response(id, "Hello - " + request.name());

simplelambda-dynamodb/README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## Simple Lambda
22

3-
Java 17+ AWS Lambda Template with Micronaut DI support with GraalVM native compatibility.
3+
Java 17+ AWS Lambda Example with Micronaut DI support with GraalVM native compatibility.
44

55
## Runtime
66

7-
Template uses [Simple Lambda](https://github.com/GoodforGod/simple-awslambda) with GraalVM native compatibility.
7+
Example uses [Simple Lambda](https://github.com/GoodforGod/simple-awslambda) with GraalVM native compatibility.
88

99
## Deploy
1010

@@ -26,4 +26,14 @@ docker run --rm --entrypoint cat simplelambda-dynamodb /home/application/functio
2626

2727
```shell
2828
sam local start-api -t sam.yaml -p 3000
29-
```
29+
```
30+
31+
## Event Example
32+
33+
Example of event to send to lambda:
34+
```json
35+
{
36+
"name": "Steeven King"
37+
}
38+
```
39+

simplelambda-dynamodb/src/main/java/io/goodforgod/simplelambda/LambdaEntrypoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @since 16.09.2021
1616
*/
1717
@ReflectionHint(types = { LogFactory.class, LogFactoryImpl.class, SimpleLog.class })
18-
@NativeImageHint(entrypoint = LambdaEntrypoint.class)
18+
@NativeImageHint(entrypoint = LambdaEntrypoint.class, name = "application")
1919
@InitializationHint(typeNames = "io.goodforgod.simplelambda")
2020
public class LambdaEntrypoint extends AbstractInputLambdaEntrypoint {
2121

Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
package io.goodforgod.simplelambda;
22

3-
import com.amazonaws.services.lambda.runtime.Context;
4-
import com.amazonaws.services.lambda.runtime.RequestHandler;
53
import io.goodforgod.aws.lambda.events.gateway.APIGatewayV2HTTPEvent;
6-
import io.goodforgod.aws.lambda.simple.EventContextBuilder;
74
import io.goodforgod.aws.lambda.simple.convert.Converter;
8-
import io.goodforgod.aws.lambda.simple.handler.EventHandler;
9-
import io.goodforgod.aws.lambda.simple.handler.impl.InputEventHandler;
10-
import io.goodforgod.aws.lambda.simple.reactive.SubscriberUtils;
11-
import io.goodforgod.aws.lambda.simple.runtime.RuntimeContext;
12-
import io.goodforgod.aws.lambda.simple.utils.InputStreamUtils;
13-
import java.io.InputStream;
14-
import java.nio.ByteBuffer;
15-
import java.util.UUID;
16-
import java.util.concurrent.Flow;
17-
import org.junit.jupiter.api.AfterAll;
5+
import io.goodforgod.aws.lambda.simple.testing.AwsLambdaAssertions;
186
import org.junit.jupiter.api.Assertions;
19-
import org.junit.jupiter.api.BeforeAll;
207
import org.junit.jupiter.api.Test;
218

229
/**
@@ -25,52 +12,33 @@
2512
*/
2613
class LambdaHandlerTests extends Assertions {
2714

28-
private static final RuntimeContext CONTEXT = new LambdaEntrypoint().getRuntimeContext();
29-
30-
@BeforeAll
31-
public static void setup() {
32-
CONTEXT.setupInRuntime();
33-
}
34-
35-
@AfterAll
36-
public static void cleanup() throws Exception {
37-
CONTEXT.close();
38-
}
39-
4015
@Test
4116
void inputEventHandled() {
42-
final EventHandler eventHandler = CONTEXT.getBean(InputEventHandler.class);
43-
final RequestHandler requestHandler = CONTEXT.getBean(RequestHandler.class);
44-
45-
final String eventAsString = "{\"name\":\"Steeven King\"}";
46-
final InputStream inputStream = InputStreamUtils.getInputStreamFromStringUTF8(eventAsString);
47-
48-
final Context eventContext = EventContextBuilder.builder().setAwsRequestId(UUID.randomUUID().toString()).build();
49-
final Flow.Publisher<ByteBuffer> publisher = eventHandler.handle(requestHandler, inputStream, eventContext);
50-
assertNotNull(publisher);
51-
52-
final String responseAsString = SubscriberUtils.getPublisherString(publisher);
53-
assertNotNull(responseAsString);
54-
assertTrue(responseAsString.contains("Hello - Steeven King"));
17+
final Request request = new Request("Steeven King");
18+
final Response response = AwsLambdaAssertions.ofEntrypoint(new LambdaEntrypoint())
19+
.input(context -> {
20+
final Converter converter = context.getBean(Converter.class);
21+
final String req = converter.toString(request);
22+
final String event = converter.toString(new APIGatewayV2HTTPEvent().setBody(req));
23+
return event.getBytes();
24+
})
25+
.expectJson(Response.class);
26+
27+
assertEquals("Hello - Steeven King", response.message());
5528
}
5629

5730
@Test
5831
void bodyEventHandled() {
59-
final EventHandler eventHandler = CONTEXT.getBean(InputEventHandler.class);
60-
final RequestHandler requestHandler = CONTEXT.getBean(RequestHandler.class);
61-
final Converter converter = CONTEXT.getBean(Converter.class);
62-
63-
final String eventBody = "{\"name\":\"Steeven King\"}";
64-
final APIGatewayV2HTTPEvent event = new APIGatewayV2HTTPEvent().setBody(eventBody);
65-
final String eventAsString = converter.toString(event);
66-
final InputStream inputStream = InputStreamUtils.getInputStreamFromStringUTF8(eventAsString);
67-
68-
final Context eventContext = EventContextBuilder.builder().setAwsRequestId(UUID.randomUUID().toString()).build();
69-
final Flow.Publisher<ByteBuffer> publisher = eventHandler.handle(requestHandler, inputStream, eventContext);
70-
assertNotNull(publisher);
71-
72-
final String responseAsString = SubscriberUtils.getPublisherString(publisher);
73-
assertNotNull(responseAsString);
74-
assertTrue(responseAsString.contains("Hello - Steeven King"));
32+
final Request request = new Request("Steeven King");
33+
final Response response = AwsLambdaAssertions.ofEntrypoint(new LambdaEntrypoint())
34+
.input(context -> {
35+
final Converter converter = context.getBean(Converter.class);
36+
final String req = converter.toString(request);
37+
final String event = converter.toString(new APIGatewayV2HTTPEvent().setBody(req));
38+
return event.getBytes();
39+
})
40+
.expectJson(Response.class);
41+
42+
assertEquals("Hello - Steeven King", response.message());
7543
}
7644
}

simplelambda-helloworld/README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## Simple Lambda
22

3-
Java 17+ AWS Lambda Template with Micronaut DI support with GraalVM native compatibility.
3+
Java 17+ AWS Lambda Example with Micronaut DI support with GraalVM native compatibility.
44

55
## Runtime
66

7-
Template uses [Simple Lambda](https://github.com/GoodforGod/simple-awslambda) with GraalVM native compatibility.
7+
Example uses [Simple Lambda](https://github.com/GoodforGod/simple-awslambda) with GraalVM native compatibility.
88

99
## Deploy
1010

@@ -26,4 +26,14 @@ docker run --rm --entrypoint cat simplelambda-helloworld /home/application/funct
2626

2727
```shell
2828
sam local start-api -t sam.yaml -p 3000
29-
```
29+
```
30+
31+
## Event Example
32+
33+
Example of event to send to lambda:
34+
```json
35+
{
36+
"name": "Steeven King"
37+
}
38+
```
39+

simplelambda-helloworld/src/main/java/io/goodforgod/simplelambda/LambdaEntrypoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @author Anton Kurako (GoodforGod)
1111
* @since 16.09.2021
1212
*/
13-
@NativeImageHint(entrypoint = LambdaEntrypoint.class)
13+
@NativeImageHint(entrypoint = LambdaEntrypoint.class, name = "application")
1414
@InitializationHint(typeNames = "io.goodforgod.simplelambda")
1515
public class LambdaEntrypoint extends AbstractInputLambdaEntrypoint {
1616

Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
package io.goodforgod.simplelambda;
22

3-
import com.amazonaws.services.lambda.runtime.Context;
4-
import com.amazonaws.services.lambda.runtime.RequestHandler;
53
import io.goodforgod.aws.lambda.events.gateway.APIGatewayV2HTTPEvent;
6-
import io.goodforgod.aws.lambda.simple.EventContextBuilder;
74
import io.goodforgod.aws.lambda.simple.convert.Converter;
8-
import io.goodforgod.aws.lambda.simple.handler.EventHandler;
9-
import io.goodforgod.aws.lambda.simple.handler.impl.BodyEventHandler;
10-
import io.goodforgod.aws.lambda.simple.handler.impl.InputEventHandler;
11-
import io.goodforgod.aws.lambda.simple.reactive.SubscriberUtils;
12-
import io.goodforgod.aws.lambda.simple.runtime.RuntimeContext;
13-
import io.goodforgod.aws.lambda.simple.utils.InputStreamUtils;
14-
import java.io.InputStream;
15-
import java.nio.ByteBuffer;
16-
import java.util.concurrent.Flow;
17-
import org.junit.jupiter.api.AfterAll;
5+
import io.goodforgod.aws.lambda.simple.testing.AwsLambdaAssertions;
186
import org.junit.jupiter.api.Assertions;
19-
import org.junit.jupiter.api.BeforeAll;
207
import org.junit.jupiter.api.Test;
218

229
/**
@@ -25,52 +12,33 @@
2512
*/
2613
class LambdaHandlerTests extends Assertions {
2714

28-
private static final RuntimeContext CONTEXT = new LambdaEntrypoint().getRuntimeContext();
29-
30-
@BeforeAll
31-
public static void setup() {
32-
CONTEXT.setupInRuntime();
33-
}
34-
35-
@AfterAll
36-
public static void cleanup() throws Exception {
37-
CONTEXT.close();
38-
}
39-
4015
@Test
4116
void inputEventHandled() {
42-
final EventHandler eventHandler = CONTEXT.getBean(InputEventHandler.class);
43-
final RequestHandler requestHandler = CONTEXT.getBean(RequestHandler.class);
44-
45-
final String eventAsString = "{\"name\":\"Steeven King\"}";
46-
final InputStream inputStream = InputStreamUtils.getInputStreamFromStringUTF8(eventAsString);
47-
48-
final Context context = EventContextBuilder.builder().build();
49-
final Flow.Publisher<ByteBuffer> publisher = eventHandler.handle(requestHandler, inputStream, context);
50-
assertNotNull(publisher);
51-
52-
final String responseAsString = SubscriberUtils.getPublisherString(publisher);
53-
assertNotNull(responseAsString);
54-
assertTrue(responseAsString.contains("Hello - Steeven King"));
17+
final Request request = new Request("Steeven King");
18+
final Response response = AwsLambdaAssertions.ofEntrypoint(new LambdaEntrypoint())
19+
.input(context -> {
20+
final Converter converter = context.getBean(Converter.class);
21+
final String req = converter.toString(request);
22+
final String event = converter.toString(new APIGatewayV2HTTPEvent().setBody(req));
23+
return event.getBytes();
24+
})
25+
.expectJson(Response.class);
26+
27+
assertEquals("Hello - Steeven King", response.message());
5528
}
5629

5730
@Test
5831
void bodyEventHandled() {
59-
final EventHandler eventHandler = CONTEXT.getBean(BodyEventHandler.class);
60-
final RequestHandler requestHandler = CONTEXT.getBean(RequestHandler.class);
61-
final Converter converter = CONTEXT.getBean(Converter.class);
62-
63-
final String eventBody = "{\"name\":\"Steeven King\"}";
64-
final APIGatewayV2HTTPEvent event = new APIGatewayV2HTTPEvent().setBody(eventBody);
65-
final String eventAsString = converter.toString(event);
66-
final InputStream inputStream = InputStreamUtils.getInputStreamFromStringUTF8(eventAsString);
67-
68-
final Context context = EventContextBuilder.builder().build();
69-
final Flow.Publisher<ByteBuffer> publisher = eventHandler.handle(requestHandler, inputStream, context);
70-
assertNotNull(publisher);
71-
72-
final String responseAsString = SubscriberUtils.getPublisherString(publisher);
73-
assertNotNull(responseAsString);
74-
assertTrue(responseAsString.contains("Hello - Steeven King"));
32+
final Request request = new Request("Steeven King");
33+
final Response response = AwsLambdaAssertions.ofEntrypoint(new LambdaEntrypoint())
34+
.input(context -> {
35+
final Converter converter = context.getBean(Converter.class);
36+
final String req = converter.toString(request);
37+
final String event = converter.toString(new APIGatewayV2HTTPEvent().setBody(req));
38+
return event.getBytes();
39+
})
40+
.expectJson(Response.class);
41+
42+
assertEquals("Hello - Steeven King", response.message());
7543
}
7644
}

simplelambda-http/README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## Simple Lambda
22

3-
Java 17+ AWS Lambda Template with Micronaut DI support with GraalVM native compatibility.
3+
Java 17+ AWS Lambda example with Micronaut DI support with GraalVM native compatibility.
44

55
## Runtime
66

7-
Template uses [Simple Lambda](https://github.com/GoodforGod/simple-awslambda) with GraalVM native compatibility.
7+
Example uses [Simple Lambda](https://github.com/GoodforGod/simple-awslambda) with GraalVM native compatibility.
88

99
## Deploy
1010

@@ -26,4 +26,14 @@ docker run --rm --entrypoint cat simplelambda-http /home/application/function.zi
2626

2727
```shell
2828
sam local start-api -t sam.yaml -p 3000
29-
```
29+
```
30+
31+
## Event Example
32+
33+
Example of event to send to lambda:
34+
```json
35+
{
36+
"name": "Steeven King"
37+
}
38+
```
39+

0 commit comments

Comments
 (0)