@@ -16,15 +16,17 @@ import org.http4k.core.Request
16
16
import org.http4k.core.Response
17
17
18
18
const val requestIdHeaderName = " lambda-runtime-aws-request-id"
19
+ const val runtimeApiEndpointVariableName = " AWS_LAMBDA_RUNTIME_API"
20
+ const val handlerVariableName = " _HANDLER"
19
21
20
22
val client: HttpHandler = JavaHttpClient ()
21
23
22
24
val json = jacksonObjectMapper().disable(DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES )
23
25
24
26
@Suppress(" UNCHECKED_CAST" )
25
27
fun main () {
26
- val runtimeApiEndpoint = System .getenv(" AWS_LAMBDA_RUNTIME_API " )
27
- val handler = System .getenv(" _HANDLER " )
28
+ val runtimeApiEndpoint = System .getenv(runtimeApiEndpointVariableName )
29
+ val handler = System .getenv(handlerVariableName )
28
30
val handlerInstance = Class .forName(handler).newInstance() as RequestHandler <ApiGatewayRequest , ApiGatewayResponse >
29
31
30
32
while (true ) {
@@ -42,12 +44,11 @@ fun main() {
42
44
}
43
45
}
44
46
47
+ // see https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html
45
48
class CustomContext (val requestId : String ): Context {
46
49
override fun getAwsRequestId (): String = requestId
47
50
48
- override fun getLogStreamName (): String {
49
- TODO (" not implemented" ) // To change body of created functions use File | Settings | File Templates.
50
- }
51
+ override fun getLogStreamName (): String = System .getenv(" AWS_LAMBDA_LOG_STREAM_NAME" )
51
52
52
53
override fun getClientContext (): ClientContext {
53
54
TODO (" not implemented" ) // To change body of created functions use File | Settings | File Templates.
@@ -69,17 +70,11 @@ class CustomContext(val requestId: String): Context {
69
70
TODO (" not implemented" ) // To change body of created functions use File | Settings | File Templates.
70
71
}
71
72
72
- override fun getMemoryLimitInMB (): Int {
73
- TODO (" not implemented" ) // To change body of created functions use File | Settings | File Templates.
74
- }
73
+ override fun getMemoryLimitInMB (): Int = System .getenv(" AWS_LAMBDA_FUNCTION_MEMORY_SIZE" ).toInt()
75
74
76
- override fun getLogGroupName (): String {
77
- TODO (" not implemented" ) // To change body of created functions use File | Settings | File Templates.
78
- }
75
+ override fun getLogGroupName (): String = System .getenv(" AWS_LAMBDA_LOG_GROUP_NAME" )
79
76
80
- override fun getFunctionVersion (): String {
81
- TODO (" not implemented" ) // To change body of created functions use File | Settings | File Templates.
82
- }
77
+ override fun getFunctionVersion (): String = System .getenv(" AWS_LAMBDA_FUNCTION_VERSION" )
83
78
84
79
override fun getIdentity (): CognitoIdentity {
85
80
TODO (" not implemented" ) // To change body of created functions use File | Settings | File Templates.
0 commit comments