Skip to content

Commit 26bd180

Browse files
committed
Update markdown
1 parent 478ac73 commit 26bd180

File tree

3 files changed

+70
-10
lines changed

3 files changed

+70
-10
lines changed

README.md

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,73 @@ including Java), visit https://maxday.github.io/lambda-perf/.
2828

2929
## Getting started
3030

31+
If you have never used AWS Lambda before, check out this getting started guide.
32+
33+
To create a simple lambda function, follow the following steps:
34+
1. Create Kotlin multiplatform project
35+
2. Include library dependency into your module-level build.gradle file
36+
```
37+
kotlin {
38+
sourceSets {
39+
nativeMain.dependencies {
40+
implementation("io.github.trueangle:lambda-runtime:0.0.1")
41+
implementation("io.github.trueangle:lambda-events:0.0.1")
42+
}
43+
}
44+
```
45+
3. Specify application entry point reference and supported targets
46+
```
47+
kotlin {
48+
//..
49+
listOf(
50+
macosArm64(),
51+
macosX64(),
52+
linuxArm64(),
53+
linuxX64(),
54+
).forEach {
55+
it.binaries {
56+
executable {
57+
entryPoint = "com.github.trueangle.knative.lambda.runtime.sample.main"
58+
}
59+
}
60+
}
61+
//..
62+
}
63+
```
64+
4. Choose lambda function type
3165
There are two types of lambda functions:
3266

33-
### Buffered handler
67+
### Buffered
68+
Buffered functions process incoming events by first collecting them
69+
into a buffer before execution. This is a default behavior.
3470

35-
tbd
71+
```
72+
class HelloWorldLambdaHandler : LambdaBufferedHandler<APIGatewayV2Request, APIGatewayV2Response> {
73+
override suspend fun handleRequest(input: APIGatewayV2Request, context: Context): APIGatewayV2Response {
74+
return APIGatewayV2Response(
75+
statusCode = 200,
76+
body = "Hello world",
77+
cookies = null,
78+
headers = null,
79+
isBase64Encoded = false
80+
)
81+
}
82+
}
83+
```
3684

37-
### Streaming handler
85+
### Streaming
86+
Streaming functions, on the other hand, process events in real-time as they arrive, without any
87+
intermediate buffering. This method is well-suited for use cases requiring immediate data
88+
processing, such as real-time analytics or event-driven architectures where low-latency responses
89+
are crucial.
3890

39-
tbd
91+
```
92+
class SampleStreamingHandler : LambdaStreamHandler<ByteArray, ByteWriteChannel> {
93+
override suspend fun handleRequest(input: ByteArray, output: ByteWriteChannel, context: Context) {
94+
ByteReadChannel(SystemFileSystem.source(Path("hello.json")).buffered()).copyTo(output)
95+
}
96+
}
97+
```
4098

4199
## Testing Runtime locally
42100

@@ -57,13 +115,16 @@ used:
57115

58116
## Logging
59117

60-
The Runtime uses AWS logging conventions for enhanced log capture, supporting String and JSON log output
118+
The Runtime uses AWS logging conventions for enhanced log capture, supporting String and JSON log
119+
output
61120
format. It also allows you to dynamically control log levels without altering your code, simplifying
62121
the debugging process. Additionally, you can direct logs to specific Amazon CloudWatch log groups,
63-
making log management and aggregation more efficient at scale. More details on how to set log format and level refer to the article.
122+
making log management and aggregation more efficient at scale. More details on how to set log format
123+
and level refer to the article.
64124
https://aws.amazon.com/blogs/compute/introducing-advanced-logging-controls-for-aws-lambda-functions/
65125

66-
To log lambda function code, use the global Log object with extension functions. The log message accepts any object / primitive type.
126+
To log lambda function code, use the global Log object with extension functions. The log message
127+
accepts any object / primitive type.
67128

68129
```
69130
Log.trace(message: T?) // The most fine-grained information used to trace the path of your code's execution
@@ -79,7 +140,6 @@ Log.error(message: T?) // Messages about problems that prevent the code from per
79140
Log.fatal(message: T?) // Messages about serious errors that cause the application to stop functioning
80141
```
81142

82-
83143
## Troubleshoot
84144

85145
- If you're going to use Amazon Linux 2023 machine, you'll need to create

sample/src/nativeMain/kotlin/com/github/trueangle/knative/lambda/runtime/sample/handler/ObjectBodyLambdaHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ObjectBodyLambdaHandler : LambdaBufferedHandler<APIGatewayV2Request, APIGa
1010
override suspend fun handleRequest(input: APIGatewayV2Request, context: Context): APIGatewayV2Response {
1111
return APIGatewayV2Response(
1212
statusCode = 200,
13-
body = "Answer is Hello world",
13+
body = "Hello world",
1414
cookies = null,
1515
headers = null,
1616
isBase64Encoded = false

sample/src/nativeMain/kotlin/com/github/trueangle/knative/lambda/runtime/sample/handler/SampleStreamingHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import kotlinx.io.files.SystemFileSystem
1111

1212
class SampleStreamingHandler : LambdaStreamHandler<ByteArray, ByteWriteChannel> {
1313
override suspend fun handleRequest(input: ByteArray, output: ByteWriteChannel, context: Context) {
14-
ByteReadChannel(SystemFileSystem.source(Path("o.json")).buffered()).copyTo(output)
14+
ByteReadChannel(SystemFileSystem.source(Path("hello.json")).buffered()).copyTo(output)
1515
}
1616
}

0 commit comments

Comments
 (0)