Skip to content

Commit

Permalink
samkgg-3 Add logging
Browse files Browse the repository at this point in the history
Updated app for AWS Lambda Powertools logging.

build.gradle
Added Powertools dependencies, which required lowering JVM target from 17 to 16 due to AspectJ limitation.

reflect-config.json, resource-config.json
Adding log4j2 makes GraalVM complain loudly. You have to add a lot to those files to get it to run without crashing.
Followed example here: https://github.com/muellerc/graalvm-sandbox/tree/main/log4j2-sandbox/src/main/resources/META-INF/native-image/com.amazonaws.sample.cmr.sns-throughput-optimization/log4j2-sandbox
From this thread: oracle/graal#2008
  • Loading branch information
Philip Yurchuk committed Sep 8, 2022
1 parent 213a871 commit b404f55
Show file tree
Hide file tree
Showing 5 changed files with 523 additions and 16 deletions.
12 changes: 10 additions & 2 deletions HelloWorldFunction/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ plugins {
id 'application'
id 'org.graalvm.buildtools.native'
id 'org.jetbrains.kotlin.jvm' version '1.7.10'
// For Spock
id 'groovy'
// For AWS Lambda Powertools
id 'java'
id 'io.freefair.aspectj.post-compile-weaving' version '6.5.1'
}

repositories {
Expand All @@ -27,6 +31,8 @@ dependencies {
testImplementation platform('org.spockframework:spock-bom:2.2-groovy-4.0')
testImplementation 'org.spockframework:spock-core'
testImplementation 'org.apache.groovy:groovy-all:4.0.4'

aspect 'software.amazon.lambda:powertools-logging:1.12.3'
}

graalvmNative {
Expand All @@ -45,12 +51,14 @@ test {

compileKotlin {
kotlinOptions {
jvmTarget = "17"
jvmTarget = "16"
}
}
sourceCompatibility = 16
targetCompatibility = 16

compileTestKotlin {
kotlinOptions {
jvmTarget = "17"
jvmTarget = "16"
}
}
6 changes: 6 additions & 0 deletions HelloWorldFunction/src/main/kotlin/helloworld/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import com.amazonaws.services.lambda.runtime.Context
import com.amazonaws.services.lambda.runtime.RequestHandler
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPResponse
import org.apache.logging.log4j.LogManager
import software.amazon.lambda.powertools.logging.Logging

/**
* Handler for requests to Lambda function.
*/
class App : RequestHandler<APIGatewayV2HTTPEvent?, APIGatewayV2HTTPResponse> {

var log = LogManager.getLogger()
@Logging
override fun handleRequest(input: APIGatewayV2HTTPEvent?, context: Context?): APIGatewayV2HTTPResponse {
log.info("Entered handleRequest.")
val headers: MutableMap<String, String> = HashMap()
headers["Content-Type"] = "application/json"
headers["X-Custom-Header"] = "application/json"
Expand Down
Loading

0 comments on commit b404f55

Please sign in to comment.