Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Lambda Advanced Configuration attribute #10591

Merged
merged 37 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1715b5e
Initial work on lambda advanced configuration
Morijarti Mar 27, 2024
001aeaf
Merge branch 'master' into feat/lambda_advanced_config
Morijarti Mar 28, 2024
e0dc939
Inital work on lambda configuration
Morijarti Apr 1, 2024
f336976
Implemented partial update of logging configuration and added new sna…
Morijarti Apr 3, 2024
6c6bc0e
Added tests for switching between LogFormats and removing / adding de…
Morijarti Apr 4, 2024
c9f7424
Updated runtime to latest version and updated snapshots
Morijarti Apr 5, 2024
5382e79
Merge branch 'refs/heads/master' into feat/lambda_advanced_config
Morijarti Apr 5, 2024
c640c18
Updated runtime to latest version and updated snapshots
Morijarti Apr 8, 2024
a53d52f
Merge branch 'refs/heads/master' into feat/lambda_advanced_config
Morijarti Apr 8, 2024
8aec7e1
Updated error message to contain ruby3.3 runtime
Morijarti Apr 8, 2024
012b3e1
Fixed regex used in info message for layer
Morijarti Apr 8, 2024
f36ed1a
Updated lambda snapshots for
Morijarti Apr 8, 2024
ee5ea63
Updated runtimes to latest version and removed LogConfiguration omiss…
Morijarti Apr 8, 2024
c5220e7
Updated snapshots for test_lambda
Morijarti Apr 8, 2024
f85d3ef
Added missing runtime
Morijarti Apr 8, 2024
5c8e166
Fixed runtime name
Morijarti Apr 9, 2024
466668d
Removed magic string fro missing runtimes
Morijarti Apr 9, 2024
205570b
Updated snapshots for test_lambda
Morijarti Apr 9, 2024
b8e3bf8
Updated snapshots for test_lambda
Morijarti Apr 10, 2024
cf83304
Merge branch 'refs/heads/master' into feat/lambda_advanced_config
Morijarti Apr 10, 2024
c7cd0a3
Removed LoggingConfig from lambda tests
Morijarti Apr 10, 2024
397e435
Updated snapshot for lambda api
Morijarti Apr 10, 2024
7b31f35
Updated snapshots for
Morijarti Apr 16, 2024
8f3143c
Updated snapshots for
Morijarti Apr 16, 2024
b9d244c
Updated snapshots for several CFn tests
Morijarti Apr 16, 2024
8275ebb
Updated test to ignore invocation mode
Morijarti Apr 16, 2024
5812232
Updated ulimits
Morijarti Apr 17, 2024
5566fd5
Updated snapshots
Morijarti Apr 17, 2024
b411101
Merge branch 'refs/heads/master' into feat/lambda_advanced_config
Morijarti Apr 17, 2024
975a02b
Updated ulimits
Morijarti Apr 17, 2024
68df531
Added warning
Morijarti Apr 17, 2024
7f6f7eb
Fixed ulimits
Morijarti Apr 17, 2024
ce466cc
Applied PR suggestions
Morijarti Apr 17, 2024
bfa94f3
Updated snapshots for newly refactored tests
Morijarti Apr 17, 2024
097cc0d
Merge branch 'refs/heads/master' into feat/lambda_advanced_config
Morijarti Apr 18, 2024
3717641
Removed obsolete snapshots
Morijarti Apr 19, 2024
034461c
Added creation of advanced lambda configuration during creation of la…
Morijarti Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions localstack/services/lambda_/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ def map_config_out(
EphemeralStorage=EphemeralStorage(Size=version.config.ephemeral_storage.size),
SnapStart=version.config.snap_start,
RuntimeVersionConfig=version.config.runtime_version_config,
LoggingConfig=version.config.logging_config,
**optional_kwargs,
)
return func_conf
Expand Down
3 changes: 3 additions & 0 deletions localstack/services/lambda_/invocation/lambda_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
InvocationType,
InvokeMode,
LastUpdateStatus,
LoggingConfig,
PackageType,
ProvisionedConcurrencyStatusEnum,
Runtime,
Expand Down Expand Up @@ -558,6 +559,8 @@ class VersionFunctionConfiguration:
# file_system_configs: FileSystemConfig
vpc_config: Optional[VpcConfig] = None

logging_config: LoggingConfig = dataclasses.field(default_factory=dict)


@dataclasses.dataclass(frozen=True)
class FunctionVersion:
Expand Down
62 changes: 61 additions & 1 deletion localstack/services/lambda_/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
ListProvisionedConcurrencyConfigsResponse,
ListTagsResponse,
ListVersionsByFunctionResponse,
LogFormat,
LoggingConfig,
LogType,
MasterRegion,
MaxFunctionEventInvokeConfigListItems,
Expand Down Expand Up @@ -636,7 +638,7 @@ def _validate_layers(self, new_layers: list[str], region: str, account_id: str):
if layer_version_str is None:
raise ValidationException(
f"1 validation error detected: Value '[{layer_version_arn}]'"
+ r" at 'layers' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 140, Member must have length greater than or equal to 1, Member must satisfy regular expression pattern: (arn:[a-zA-Z0-9-]+:lambda:[a-zA-Z0-9-]+:\d{12}:layer:[a-zA-Z0-9-_]+:[0-9]+)|(arn:[a-zA-Z0-9-]+:lambda:::awslayer:[a-zA-Z0-9-_]+), Member must not be null]",
+ r" at 'layers' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 140, Member must have length greater than or equal to 1, Member must satisfy regular expression pattern: (arn:[a-zA-Z0-9-]+:lambda:[a-z]{2}((-gov)|(-iso(b?)))?-[a-z]+-\d{1}:\d{12}:layer:[a-zA-Z0-9-_]+:[0-9]+)|(arn:[a-zA-Z0-9-]+:lambda:::awslayer:[a-zA-Z0-9-_]+), Member must not be null]",
)

state = lambda_stores[layer_account_id][layer_region]
Expand Down Expand Up @@ -867,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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glad we caught that one 😃

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 @@ -906,6 +935,7 @@ def create_function(
code=StateReasonCode.Creating,
reason="The function is being created.",
),
logging_config=logging_config,
),
)
fn.versions["$LATEST"] = version
Expand Down Expand Up @@ -1044,6 +1074,36 @@ def update_function_configuration(
working_directory=new_image_config.get("WorkingDirectory"),
)

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",
} | logging_config

last_config = latest_version_config.logging_config

# add partial update
new_logging_config = last_config | logging_config

# in case we switched from JSON to Text we need to remove LogLevel keys
if (
new_logging_config.get("LogFormat") == LogFormat.Text
and last_config.get("LogFormat") == LogFormat.JSON
):
new_logging_config.pop("ApplicationLogLevel", None)
new_logging_config.pop("SystemLogLevel", None)

replace_kwargs["logging_config"] = new_logging_config

if "TracingConfig" in request:
new_mode = request.get("TracingConfig", {}).get("Mode")
if new_mode:
Expand Down
4 changes: 2 additions & 2 deletions localstack/services/lambda_/runtimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
SUPPORTED_RUNTIMES: list[Runtime] = list(set(IMAGE_MAPPING.keys()) - set(DEPRECATED_RUNTIMES))

# A temporary list of missing runtimes not yet supported in LocalStack. Used for modular updates.
MISSING_RUNTIMES = []
MISSING_RUNTIMES = [Runtime.ruby3_3]

# An unordered list of all Lambda runtimes supported by LocalStack.
ALL_RUNTIMES: list[Runtime] = list(IMAGE_MAPPING.keys())
Expand Down Expand Up @@ -130,6 +130,6 @@
SNAP_START_SUPPORTED_RUNTIMES = [Runtime.java11, Runtime.java17, Runtime.java21]

# An ordered list of all Lambda runtimes considered valid by AWS. Matching snapshots in test_create_lambda_exceptions
VALID_RUNTIMES: str = "[nodejs20.x, provided.al2023, python3.12, java17, nodejs16.x, dotnet8, python3.10, java11, python3.11, dotnet6, java21, nodejs18.x, provided.al2, java8.al2, ruby3.2, python3.8, python3.9]"
VALID_RUNTIMES: str = "[nodejs20.x, provided.al2023, python3.12, java17, nodejs16.x, dotnet8, python3.10, java11, python3.11, dotnet6, java21, nodejs18.x, provided.al2, ruby3.3, java8.al2, ruby3.2, python3.8, python3.9]"
# An ordered list of all Lambda runtimes for layers considered valid by AWS. Matching snapshots in test_layer_exceptions
VALID_LAYER_RUNTIMES: str = "[ruby2.6, dotnetcore1.0, python3.7, nodejs8.10, nasa, ruby2.7, python2.7-greengrass, dotnetcore2.0, python3.8, java21, dotnet6, dotnetcore2.1, python3.9, java11, nodejs6.10, provided, dotnetcore3.1, dotnet8, java17, nodejs, nodejs4.3, java8.al2, go1.x, nodejs20.x, go1.9, byol, nodejs10.x, provided.al2023, python3.10, java8, nodejs12.x, python3.11, nodejs8.x, python3.12, nodejs14.x, nodejs8.9, python3.13, nodejs16.x, provided.al2, nodejs4.3-edge, nodejs18.x, ruby3.2, python3.4, ruby3.3, ruby2.5, python3.6, python2.7]"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tests/aws/scenario/lambda_destination/test_lambda_destination_scenario.py::TestLambdaDestinationScenario::test_infra": {
"recorded-date": "04-10-2023, 16:04:47",
"recorded-date": "17-04-2024, 07:04:49",
"recorded-content": {
"get_fn_1": {
"Code": {
Expand All @@ -22,6 +22,10 @@
"Handler": "index.handler",
"LastModified": "date",
"LastUpdateStatus": "Successful",
"LoggingConfig": {
"LogFormat": "Text",
"LogGroup": "/aws/lambda/<function-name:1>"
},
"MemorySize": 128,
"PackageType": "Zip",
"RevisionId": "<uuid:1>",
Expand Down Expand Up @@ -71,6 +75,10 @@
"Handler": "index.handler",
"LastModified": "date",
"LastUpdateStatus": "Successful",
"LoggingConfig": {
"LogFormat": "Text",
"LogGroup": "/aws/lambda/<function-name:2>"
},
"MemorySize": 128,
"PackageType": "Zip",
"RevisionId": "<uuid:2>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"last_validated_date": "2023-10-04T14:05:34+00:00"
},
"tests/aws/scenario/lambda_destination/test_lambda_destination_scenario.py::TestLambdaDestinationScenario::test_infra": {
"last_validated_date": "2023-10-04T14:04:47+00:00"
"last_validated_date": "2024-04-17T07:04:49+00:00"
}
}
22 changes: 21 additions & 1 deletion tests/aws/scenario/note_taking/test_note_taking.snapshot.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tests/aws/scenario/note_taking/test_note_taking.py::TestNoteTakingScenario::test_validate_infra_setup": {
"recorded-date": "28-09-2023, 16:08:28",
"recorded-date": "16-04-2024, 08:42:29",
"recorded-content": {
"describe_stack_resources": {
"StackResources": [
Expand Down Expand Up @@ -536,6 +536,10 @@
"Handler": "index.handler",
"LastModified": "date",
"LastUpdateStatus": "Successful",
"LoggingConfig": {
"LogFormat": "Text",
"LogGroup": "/aws/lambda/<function-name:1>"
},
"MemorySize": 128,
"PackageType": "Zip",
"RevisionId": "<uuid:2>",
Expand Down Expand Up @@ -590,6 +594,10 @@
"Handler": "index.handler",
"LastModified": "date",
"LastUpdateStatus": "Successful",
"LoggingConfig": {
"LogFormat": "Text",
"LogGroup": "/aws/lambda/<function-name:2>"
},
"MemorySize": 128,
"PackageType": "Zip",
"RevisionId": "<uuid:3>",
Expand Down Expand Up @@ -644,6 +652,10 @@
"Handler": "index.handler",
"LastModified": "date",
"LastUpdateStatus": "Successful",
"LoggingConfig": {
"LogFormat": "Text",
"LogGroup": "/aws/lambda/<function-name:3>"
},
"MemorySize": 128,
"PackageType": "Zip",
"RevisionId": "<uuid:4>",
Expand Down Expand Up @@ -698,6 +710,10 @@
"Handler": "index.handler",
"LastModified": "date",
"LastUpdateStatus": "Successful",
"LoggingConfig": {
"LogFormat": "Text",
"LogGroup": "/aws/lambda/<function-name:4>"
},
"MemorySize": 128,
"PackageType": "Zip",
"RevisionId": "<uuid:5>",
Expand Down Expand Up @@ -752,6 +768,10 @@
"Handler": "index.handler",
"LastModified": "date",
"LastUpdateStatus": "Successful",
"LoggingConfig": {
"LogFormat": "Text",
"LogGroup": "/aws/lambda/<function-name:5>"
},
"MemorySize": 128,
"PackageType": "Zip",
"RevisionId": "<uuid:6>",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"tests/aws/scenario/note_taking/test_note_taking.py::TestNoteTakingScenario::test_validate_infra_setup": {
"last_validated_date": "2023-09-28T14:08:28+00:00"
"last_validated_date": "2024-04-16T08:42:29+00:00"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def test_lambda_w_dynamodb_event_filter_update(deploy_cfn_template, snapshot, aw
"$..access-control-expose-headers",
"$..server",
"$..content-length",
"$..InvokeMode",
Morijarti marked this conversation as resolved.
Show resolved Hide resolved
]
)
@markers.aws.validated
Expand Down