Skip to content

Commit d54c186

Browse files
committed
Update doc
1 parent 87cca46 commit d54c186

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

README.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ 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-
3331
To create a simple lambda function, follow the following steps:
3432

3533
1. Create Kotlin multiplatform project
@@ -116,19 +114,23 @@ class SampleStreamingHandler : LambdaStreamHandler<ByteArray, ByteWriteChannel>
116114
}
117115
```
118116

119-
5. Specify application entry point using standard `main`. Call `LambdaRuntime.run` to execute Lambda
117+
5. Specify application entry point using standard `main` function. Call `LambdaRuntime.run` to
118+
execute Lambda
120119
by passing handler to it.
121120

122121
```kotlin
123122
fun main() = LambdaRuntime.run { HelloWorldLambdaHandler() }
124123
```
125124

125+
For SampleStreamingHandler
126+
126127
```kotlin
127-
// or SampleStreamingHandler for streaming lambda
128128
fun main() = LambdaRuntime.run { SampleStreamingHandler() }
129129

130130
```
131131

132+
For more examples refer to project's sample.
133+
132134
## Testing Runtime locally
133135

134136
To run local runtime
@@ -146,6 +148,39 @@ used:
146148

147149
## Build and deploy to AWS
148150

151+
1. Execute `./gradlew build`
152+
2. After successful build execute `cd YOUR_MODULE/build/bin/linuxX64/releaseExecutable/` this will
153+
locate Lambda handler's executable file, e.g. `YOUR_MODULE.kexe`. The name of the file (including
154+
the extension) will be used as `handler` name. Don't forget to specify it upon
155+
lambda-function creation.
156+
3.
157+
Execute `(echo '#!/bin/sh' > bootstrap && echo './"$_HANDLER"' >> bootstrap && chmod +x bootstrap && zip -r bootstrap.zip ./*)`
158+
4. Deploy bootstrap.zip archive to AWS. If you have never used AWS Lambda
159+
before, [learn how to deploy Lambda function as zip archive manually](https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-zip.html)
160+
or
161+
using [AWS CLI](https://docs.aws.amazon.com/codedeploy/latest/userguide/getting-started-codedeploy.html):
162+
163+
```bash
164+
$ aws lambda create-function --function-name sample \
165+
--handler sample.kexe \ # Important to specify the name of the Lambda\'s executable
166+
--zip-file bootstrap.zip \
167+
--runtime provided.al2023 \ # Change this to provided.al2 if you would like to use Amazon Linux 2
168+
--role arn:aws:iam::XXXXXXXXXXXXX:role/your_lambda_execution_role \
169+
--environment Variables={RUST_BACKTRACE=1} \
170+
--tracing-config Mode=Active
171+
```
172+
173+
You can now test the function using the AWS CLI or the AWS Lambda console
174+
175+
```bash
176+
$ aws lambda invoke
177+
--cli-binary-format raw-in-base64-out \
178+
--function-name sample \
179+
--payload '{"command": "Say Hi!"}' \
180+
output.json
181+
$ cat output.json
182+
```
183+
149184
## Logging
150185

151186
The Runtime uses AWS logging conventions for enhanced log capture, supporting String and JSON log
@@ -194,10 +229,11 @@ Log.fatal(message: T?) // Messages about serious errors that cause the applicati
194229
machine [uses different curl version from what is requested by the runtime](https://youtrack.jetbrains.com/issue/KTOR-6361/Curl-Error-linking-curl-in-linkDebugExecutableLinuxX64-on-macOS).
195230
To solve that either
196231
use [Gihub Actions workflow](https://github.com/trueangle/kotlin-native-aws-lambda-runtime/actions/workflows/buildLinux86_64.yml)
197-
or local docker container with ubuntu 22 under the hood. Example:
198-
```bash
232+
or local docker container with ubuntu 22 under the hood. Example [Dockerfile](Dockerfile) and
233+
build command:
234+
235+
```bash
199236

200237
docker build -t sample .
201238
docker run --rm -v $(pwd):/sample -w /sample sample ./gradlew build
202-
203239
```

0 commit comments

Comments
 (0)