Skip to content

Commit

Permalink
Added creation of advanced lambda configuration during creation of la…
Browse files Browse the repository at this point in the history
…mbda
  • Loading branch information
Morijarti committed Apr 19, 2024
1 parent 3717641 commit 034461c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
31 changes: 28 additions & 3 deletions localstack/services/lambda_/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,33 @@ def create_function(
)
# Runtime management controls are not available when providing a custom image
runtime_version_config = None
if "LoggingConfig" in request:
logging_config = request["LoggingConfig"]
LOG.warning(
"Advanced Lambda Logging Configuration is currently mocked "
"and will not impact the logging behavior. "
"Please create a feature request if needed."
)

# when switching to JSON, app and system level log is auto set to INFO
if logging_config.get("LogFormat", None) == LogFormat.JSON:
logging_config = {
"ApplicationLogLevel": "INFO",
"SystemLogLevel": "INFO",
"LogGroup": f"/aws/lambda/{function_name}",
} | logging_config
else:
logging_config = (
LoggingConfig(
LogFormat=LogFormat.Text, LogGroup=f"/aws/lambda/{function_name}"
)
| logging_config
)

else:
logging_config = LoggingConfig(
LogFormat=LogFormat.Text, LogGroup=f"/aws/lambda/{function_name}"
)

version = FunctionVersion(
id=arn,
Expand Down Expand Up @@ -908,9 +935,7 @@ def create_function(
code=StateReasonCode.Creating,
reason="The function is being created.",
),
logging_config=LoggingConfig(
LogFormat=LogFormat.Text, LogGroup=f"/aws/lambda/{function_name}"
),
logging_config=logging_config,
),
)
fn.versions["$LATEST"] = version
Expand Down
3 changes: 3 additions & 0 deletions tests/aws/services/lambda_/test_lambda_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def test_function_advanced_logging_configuration(
role=lambda_su_role,
MemorySize=256,
Timeout=5,
LoggingConfig={
"LogFormat": LogFormat.JSON,
},
)

snapshot.match("create_response", create_response)
Expand Down
20 changes: 13 additions & 7 deletions tests/aws/services/lambda_/test_lambda_api.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -14615,7 +14615,7 @@
}
},
"tests/aws/services/lambda_/test_lambda_api.py::TestLoggingConfig::test_function_advanced_logging_configuration": {
"recorded-date": "17-04-2024, 14:16:48",
"recorded-date": "19-04-2024, 08:20:18",
"recorded-content": {
"create_response": {
"CreateEventSourceMappingResponse": null,
Expand All @@ -14637,8 +14637,10 @@
"Handler": "handler.handler",
"LastModified": "date",
"LoggingConfig": {
"LogFormat": "Text",
"LogGroup": "/aws/lambda/<function-name:1>"
"ApplicationLogLevel": "INFO",
"LogFormat": "JSON",
"LogGroup": "/aws/lambda/<function-name:1>",
"SystemLogLevel": "INFO"
},
"MemorySize": 256,
"PackageType": "Zip",
Expand Down Expand Up @@ -14690,8 +14692,10 @@
"LastModified": "date",
"LastUpdateStatus": "Successful",
"LoggingConfig": {
"LogFormat": "Text",
"LogGroup": "/aws/lambda/<function-name:1>"
"ApplicationLogLevel": "INFO",
"LogFormat": "JSON",
"LogGroup": "/aws/lambda/<function-name:1>",
"SystemLogLevel": "INFO"
},
"MemorySize": 256,
"PackageType": "Zip",
Expand Down Expand Up @@ -14736,8 +14740,10 @@
"LastModified": "date",
"LastUpdateStatus": "Successful",
"LoggingConfig": {
"LogFormat": "Text",
"LogGroup": "/aws/lambda/<function-name:1>"
"ApplicationLogLevel": "INFO",
"LogFormat": "JSON",
"LogGroup": "/aws/lambda/<function-name:1>",
"SystemLogLevel": "INFO"
},
"MemorySize": 256,
"PackageType": "Zip",
Expand Down
2 changes: 1 addition & 1 deletion tests/aws/services/lambda_/test_lambda_api.validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
"last_validated_date": "2024-04-17T14:16:55+00:00"
},
"tests/aws/services/lambda_/test_lambda_api.py::TestLoggingConfig::test_function_advanced_logging_configuration": {
"last_validated_date": "2024-04-17T14:16:47+00:00"
"last_validated_date": "2024-04-19T08:20:18+00:00"
},
"tests/aws/services/lambda_/test_lambda_api.py::TestLoggingConfig::test_function_partial_advanced_logging_configuration_update[partial_config0]": {
"last_validated_date": "2024-04-17T14:17:00+00:00"
Expand Down

0 comments on commit 034461c

Please sign in to comment.