@@ -41,49 +41,67 @@ final class LambdaEnvironment(
41
41
.orElse(systemVariables.get(key))
42
42
)
43
43
44
+ /** The host and port of the runtime API. */
44
45
private def getRuntimeApi (): String =
45
46
getProperty(" AWS_LAMBDA_RUNTIME_API" )
46
47
48
+ /** The name of the function. */
47
49
final def getFunctionName (): String =
48
50
getProperty(" AWS_LAMBDA_FUNCTION_NAME" )
49
51
52
+ /** The version of the function being executed. */
50
53
final def getFunctionVersion (): String =
51
54
getProperty(" AWS_LAMBDA_FUNCTION_VERSION" )
52
55
56
+ /** The amount of memory available to the function in MB. */
53
57
final def getMemoryLimitInMB (): Int =
54
58
getProperty(" AWS_LAMBDA_FUNCTION_MEMORY_SIZE" ).toInt
55
59
60
+ /** The name of the Amazon CloudWatch Logs group for the function. */
56
61
final def getLogGroupName (): String =
57
62
getProperty(" AWS_LAMBDA_LOG_GROUP_NAME" )
58
63
64
+ /** The name of the Amazon CloudWatch Logs stream for the function. */
59
65
final def getLogStreamName (): String =
60
66
getProperty(" AWS_LAMBDA_LOG_STREAM_NAME" )
61
67
68
+ /** The path to your Lambda function code. */
69
+ final def getLambdaRuntimeDir (): String =
70
+ getProperty(" LAMBDA_RUNTIME_DIR" )
71
+
72
+ /** The path to runtime libraries. */
73
+ final def getLambdaTaskRoot (): String =
74
+ getProperty(" LAMBDA_TASK_ROOT" )
75
+
76
+ /** Returns true when runs deployed to AWS Lambda */
77
+ final val isHostedAwsEnvironment : Boolean =
78
+ maybeGetProperty(" _HANDLER" ).isDefined
79
+
62
80
final val isDebugMode : Boolean =
63
81
maybeGetProperty(" LAMBDA_RUNTIME_DEBUG_MODE" )
64
82
.map(parseBooleanFlagDefaultOff)
65
- .getOrElse(false )
83
+ .getOrElse(true )
66
84
67
85
final val isTraceMode : Boolean =
68
86
maybeGetProperty(" LAMBDA_RUNTIME_TRACE_MODE" )
69
87
.map(parseBooleanFlagDefaultOff)
70
- .getOrElse(false )
88
+ .getOrElse(! isHostedAwsEnvironment )
71
89
72
90
final val shouldDisplayAnsiColors : Boolean =
73
91
maybeGetProperty(" ANSI_COLORS_MODE" )
74
- .map(parseBooleanFlagDefaultOn )
92
+ .map(parseBooleanFlagDefault( ! isHostedAwsEnvironment) )
75
93
.getOrElse(maybeGetProperty(" NO_COLOR" ).forall(p => p.trim() != " 1" ))
76
94
77
95
final val shouldLogStructuredJson : Boolean =
78
96
! shouldDisplayAnsiColors &&
79
97
maybeGetProperty(" LAMBDA_RUNTIME_LOG_TYPE" )
80
98
.map(_.toUpperCase().contains(" STRUCTURED" ))
81
- .getOrElse(true )
99
+ .getOrElse(isHostedAwsEnvironment )
82
100
83
101
final val shouldLogInJsonArrayFormat : Boolean =
84
102
maybeGetProperty(" LAMBDA_RUNTIME_LOG_FORMAT" )
85
103
.map(_.toUpperCase().contains(" JSON_ARRAY" ))
86
- .getOrElse(true )
104
+ .getOrElse(isHostedAwsEnvironment )
87
105
88
106
final val shouldLogInJsonStringFormat : Boolean =
89
107
maybeGetProperty(" LAMBDA_RUNTIME_LOG_FORMAT" )
@@ -156,18 +174,25 @@ final class LambdaEnvironment(
156
174
)
157
175
158
176
final inline def parseBooleanFlagDefaultOff : String => Boolean = s =>
159
- s.toLowerCase() match {
177
+ s.trim(). toLowerCase() match {
160
178
case " true" => true
161
179
case " on" => true
162
180
case _ => false
163
181
}
164
182
165
183
final inline def parseBooleanFlagDefaultOn : String => Boolean = s =>
166
- s.toLowerCase() match {
184
+ s.trim(). toLowerCase() match {
167
185
case " false" => false
168
186
case " off" => false
169
187
case _ => true
170
188
}
189
+
190
+ final inline def parseBooleanFlagDefault (default : Boolean ): String => Boolean = s =>
191
+ s.trim().toLowerCase() match {
192
+ case " false" => false
193
+ case " off" => false
194
+ case _ => default
195
+ }
171
196
}
172
197
173
198
object LambdaEnvironment {
0 commit comments