Skip to content

Commit 9290872

Browse files
authored
Merge branch 'develop' into feat-java25-python314
2 parents b88851f + 88e3dd1 commit 9290872

14 files changed

Lines changed: 260 additions & 33 deletions

File tree

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ init:
1313
fi
1414

1515
test:
16-
# Run unit tests
17-
# Fail if coverage falls below 95%
16+
# Run unit tests and fail if coverage falls below 94%
1817
pytest --cov samcli --cov schema --cov-report term-missing --cov-fail-under 94 tests/unit
1918

2019
test-cov-report:

requirements/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ aws-sam-translator==1.101.0
1111
docker~=7.1.0
1212
dateparser~=1.2
1313
requests~=2.32.5
14-
aws_lambda_builders==1.58.0
14+
aws_lambda_builders==1.59.0
1515
tomlkit==0.13.3
1616
# NOTE: For supporting watchdog in Python3.8, version is pinned to 4.0.2 as
1717
# version 5.0.2 introduced some breaking changes for versions > Python3.8

requirements/reproducible-linux.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ attrs==25.4.0 \
1818
# via
1919
# jsonschema
2020
# referencing
21-
aws-lambda-builders==1.58.0 \
22-
--hash=sha256:95bf2a502bd9cf5abc14b1a27e9d0c7378cf261abb52373ea16be7ca22b7e812 \
23-
--hash=sha256:e096f8126e67341f6d24791f933d186745c97d3cbf156122df732436a4c03010
21+
aws-lambda-builders==1.59.0 \
22+
--hash=sha256:87b3ac37598418e8d41c1c65bfd90768ad6737da73585d645274b9bdb1122565 \
23+
--hash=sha256:d863db6b6fcf1377bd6e4b2eb5443874b839ffa65d4cde2b531c8c2120bd99e3
2424
# via aws-sam-cli (setup.py)
2525
aws-sam-translator==1.101.0 \
2626
--hash=sha256:234c1ca29d47f2cd276858371d4a646bc5cdb0de1e07724721d9358d6de005aa \

requirements/reproducible-mac.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ attrs==25.4.0 \
1818
# via
1919
# jsonschema
2020
# referencing
21-
aws-lambda-builders==1.58.0 \
22-
--hash=sha256:95bf2a502bd9cf5abc14b1a27e9d0c7378cf261abb52373ea16be7ca22b7e812 \
23-
--hash=sha256:e096f8126e67341f6d24791f933d186745c97d3cbf156122df732436a4c03010
21+
aws-lambda-builders==1.59.0 \
22+
--hash=sha256:87b3ac37598418e8d41c1c65bfd90768ad6737da73585d645274b9bdb1122565 \
23+
--hash=sha256:d863db6b6fcf1377bd6e4b2eb5443874b839ffa65d4cde2b531c8c2120bd99e3
2424
# via aws-sam-cli (setup.py)
2525
aws-sam-translator==1.101.0 \
2626
--hash=sha256:234c1ca29d47f2cd276858371d4a646bc5cdb0de1e07724721d9358d6de005aa \

requirements/reproducible-win.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ attrs==25.4.0 \
1818
# via
1919
# jsonschema
2020
# referencing
21-
aws-lambda-builders==1.58.0 \
22-
--hash=sha256:95bf2a502bd9cf5abc14b1a27e9d0c7378cf261abb52373ea16be7ca22b7e812 \
23-
--hash=sha256:e096f8126e67341f6d24791f933d186745c97d3cbf156122df732436a4c03010
21+
aws-lambda-builders==1.59.0 \
22+
--hash=sha256:87b3ac37598418e8d41c1c65bfd90768ad6737da73585d645274b9bdb1122565 \
23+
--hash=sha256:d863db6b6fcf1377bd6e4b2eb5443874b839ffa65d4cde2b531c8c2120bd99e3
2424
# via aws-sam-cli (setup.py)
2525
aws-sam-translator==1.101.0 \
2626
--hash=sha256:234c1ca29d47f2cd276858371d4a646bc5cdb0de1e07724721d9358d6de005aa \

samcli/commands/remote/invoke/cli.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,15 @@ def do_cli(
166166
and remote_invoke_context.resource_summary
167167
and remote_invoke_context.resource_summary.resource_type == AWS_LAMBDA_FUNCTION
168168
):
169-
lambda_test_event = remote_invoke_context.get_lambda_shared_test_event_provider()
170169
LOG.debug("Retrieving remote event %s", test_event_name)
171-
event = lambda_test_event.get_event(test_event_name, remote_invoke_context.resource_summary)
170+
lambda_test_event = remote_invoke_context.get_lambda_shared_test_event_provider().get_event(
171+
test_event_name, remote_invoke_context.resource_summary
172+
)
173+
event = lambda_test_event["json"]
172174
LOG.debug("Remote event contents: %s", event)
175+
metadata = lambda_test_event["metadata"]
176+
if "invocationType" in metadata:
177+
parameter.setdefault("InvocationType", metadata["invocationType"])
173178
elif test_event_name:
174179
LOG.info("Note: remote event is only supported for AWS Lambda Function resource.")
175180
test_event_name = ""

samcli/commands/remote/test_event/get/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def do_cli(
127127
raise UserException(str(ex), wrapped_from=ex.__class__.__name__) from ex
128128

129129
LOG.debug("Getting remote event '%s' for resource: %s", name, function_resource)
130-
event = lambda_test_event.get_event(name, function_resource)
130+
event = lambda_test_event.get_event(name, function_resource)["json"]
131131

132132
try:
133133
output_file.write(event)

samcli/commands/remote/test_event/put/cli.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from samcli.cli.cli_config_file import ConfigProvider, configuration_option
1212
from samcli.cli.context import Context
1313
from samcli.cli.main import aws_creds_options, common_options, pass_context, print_cmdline_args
14+
from samcli.commands._utils.click_mutex import ClickMutex
1415
from samcli.commands._utils.command_exception_handler import command_exception_handler
1516
from samcli.commands.remote.exceptions import IllFormedEventData
1617
from samcli.commands.remote.test_event.put.core.command import RemoteTestEventPutCommand
@@ -19,6 +20,7 @@
1920
stack_name_or_resource_id_atleast_one_option_validation,
2021
)
2122
from samcli.lib.telemetry.metric import track_command
23+
from samcli.lib.utils.invocation_type import EVENT, REQUEST_RESPONSE
2224
from samcli.lib.utils.version_checker import check_newer_version
2325
from samcli.yamlhelper import yaml_parse
2426

@@ -56,6 +58,14 @@
5658
"The option '--file' is required (You can provide '-' to read from stdin)"
5759
),
5860
)
61+
@click.option(
62+
"--invocation-type",
63+
type=click.Choice([EVENT, REQUEST_RESPONSE]),
64+
replace_help_option="--invocation-type INVOCATION_TYPE",
65+
help="Lambda function invocation type."
66+
+ click.style(f"\n\nInvocation types: {[EVENT, REQUEST_RESPONSE]}", bold=True),
67+
cls=ClickMutex,
68+
)
5969
@click.option("--force", "-f", is_flag=True, help="Force saving the event even if it already exists")
6070
@click.argument("resource-id", required=False)
6171
@aws_creds_options
@@ -72,6 +82,7 @@ def cli(
7282
resource_id: Optional[str],
7383
name: str,
7484
file: TextIOWrapper,
85+
invocation_type: str,
7586
force: bool,
7687
config_file: str,
7788
config_env: str,
@@ -84,6 +95,7 @@ def cli(
8495
resource_id,
8596
name,
8697
file,
98+
invocation_type,
8799
force,
88100
ctx.region,
89101
ctx.profile,
@@ -97,6 +109,7 @@ def do_cli(
97109
resource_id: Optional[str],
98110
name: str,
99111
file: TextIOWrapper,
112+
invocation_type: str,
100113
force: bool,
101114
region: str,
102115
profile: str,
@@ -147,7 +160,7 @@ def do_cli(
147160
data = yaml_parse(contents)
148161
event_data = json.dumps(data)
149162
LOG.debug("Creating remote event %s from resource: %s", name, function_resource)
150-
lambda_test_event.create_event(name, function_resource, event_data, force=force)
163+
lambda_test_event.create_event(name, function_resource, event_data, invocation_type, force=force)
151164
click.echo(f"Put remote event '{name}' completed successfully")
152165
except (ValueError, YAMLError, JSONDecodeError) as ex:
153166
raise IllFormedEventData(f"File {file.name} doesn't contain a valid JSON:\n {ex}") from ex

samcli/commands/remote/test_event/put/core/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# NOTE: The ordering of the option lists matter, they are the order
1919
# in which options will be displayed.
2020

21-
EVENT_OPTIONS: List[str] = ["name", "file", "force"]
21+
EVENT_OPTIONS: List[str] = ["name", "file", "invocation_type", "force"]
2222

2323
ALL_OPTIONS: List[str] = (
2424
INFRASTRUCTURE_OPTION_NAMES

samcli/lib/shared_test_events/lambda_shared_test_event.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import logging
55
from json import JSONDecodeError
6-
from typing import Any
6+
from typing import Any, Optional
77

88
import botocore
99

@@ -17,6 +17,7 @@
1717
)
1818
from samcli.lib.schemas.schemas_api_caller import SchemasApiCaller
1919
from samcli.lib.utils.cloudformation import CloudFormationResourceSummary
20+
from samcli.lib.utils.invocation_type import REQUEST_RESPONSE
2021
from samcli.lib.utils.resources import AWS_LAMBDA_FUNCTION
2122

2223
LAMBDA_TEST_EVENT_REGISTRY = "lambda-testevent-schemas"
@@ -142,7 +143,14 @@ def limit_versions(self, schema_name: str, registry_name: str = LAMBDA_TEST_EVEN
142143
)
143144
self._api_caller.delete_version(registry_name, schema_name, version_to_delete)
144145

145-
def add_event_to_schema(self, schema: str, event: str, event_name: str, replace_if_exists: bool = False) -> str:
146+
def add_event_to_schema(
147+
self,
148+
schema: str,
149+
event: str,
150+
event_name: str,
151+
metadata: Optional[dict[str, str]],
152+
replace_if_exists: bool = False,
153+
) -> str:
146154
"""
147155
Adds an event to a schema
148156
@@ -176,6 +184,8 @@ def add_event_to_schema(self, schema: str, event: str, event_name: str, replace_
176184
schema_dict["components"]["examples"][event_name] = {
177185
"value": event_dict,
178186
}
187+
if metadata:
188+
schema_dict["components"]["examples"][event_name]["x-metadata"] = metadata
179189

180190
schema = json.dumps(schema_dict)
181191

@@ -200,7 +210,7 @@ def get_event_from_schema(self, schema: str, event_name: str) -> Any:
200210
the name of the event to retrieve from the schema
201211
Returns
202212
-------
203-
The event data of the event "event_name"
213+
The event data and metadata of the event "event_name"
204214
"""
205215
try:
206216
schema_dict = json.loads(schema)
@@ -211,7 +221,7 @@ def get_event_from_schema(self, schema: str, event_name: str) -> Any:
211221
raise ResourceNotFound(f"Event {event_name} not found")
212222

213223
# can use square brackets here since we know each of these subdicts exist
214-
return existing_events[event_name]["value"]
224+
return existing_events[event_name]
215225

216226
except JSONDecodeError as ex:
217227
LOG.error("Error decoding schema when getting event %s", event_name)
@@ -263,6 +273,7 @@ def create_event(
263273
event_name: str,
264274
function_resource: CloudFormationResourceSummary,
265275
event_data: str,
276+
invocation_type: str = REQUEST_RESPONSE,
266277
force: bool = False,
267278
registry_name: str = LAMBDA_TEST_EVENT_REGISTRY,
268279
) -> str:
@@ -277,6 +288,8 @@ def create_event(
277288
The function where the event will be created
278289
event_data: str
279290
The JSON data of the event to be created
291+
invocation_type: str
292+
The Lambda invocation type of the event to be created
280293
registry_name: str
281294
The name of the registry that contains the schema
282295
"""
@@ -287,16 +300,19 @@ def create_event(
287300

288301
schema_name = self._get_schema_name(function_resource)
289302
original_schema = api_caller.get_schema(registry_name, schema_name)
303+
metadata = {"invocationType": invocation_type}
290304

291305
if original_schema:
292306
LOG.debug("Schema %s already exists, adding event %s", schema_name, event_name)
293307
self.limit_versions(schema_name, registry_name)
294-
schema = self.add_event_to_schema(original_schema, event_data, event_name, replace_if_exists=force)
308+
schema = self.add_event_to_schema(
309+
original_schema, event_data, event_name, metadata, replace_if_exists=force
310+
)
295311
api_caller.update_schema(schema, registry_name, schema_name, OPEN_API_TYPE)
296312
else:
297313
LOG.debug("Schema %s does not already exist, creating new", schema_name)
298314
schema = api_caller.discover_schema(event_data, OPEN_API_TYPE)
299-
schema = self.add_event_to_schema(schema, event_data, event_name)
315+
schema = self.add_event_to_schema(schema, event_data, event_name, metadata)
300316
api_caller.create_schema(schema, registry_name, schema_name, OPEN_API_TYPE)
301317

302318
return schema
@@ -346,7 +362,7 @@ def get_event(
346362
event_name: str,
347363
function_resource: CloudFormationResourceSummary,
348364
registry_name: str = LAMBDA_TEST_EVENT_REGISTRY,
349-
) -> str:
365+
) -> Any:
350366
"""
351367
Returns a remote test event
352368
@@ -360,7 +376,7 @@ def get_event(
360376
The name of the registry that contains the schema
361377
Returns
362378
-------
363-
The JSON data of the event
379+
The parsed JSON data and metadata of the event
364380
"""
365381
api_caller = self._api_caller
366382

@@ -377,7 +393,7 @@ def get_event(
377393
event = self.get_event_from_schema(schema, event_name)
378394

379395
try:
380-
return json.dumps(event)
396+
return {"json": json.dumps(event["value"]), "metadata": event.get("x-metadata", {})}
381397

382398
except JSONDecodeError as ex:
383399
LOG.error("Error parsing event %s from schema %s", event_name, schema_name)

0 commit comments

Comments
 (0)