Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 15 additions & 38 deletions tests/aws/services/cloudformation/resources/test_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
from localstack.utils.testutil import create_lambda_archive, get_lambda_log_events


# TODO: Fix for new Lambda provider (was tested for old provider)
@pytest.mark.skip(reason="not implemented yet in new provider")
@markers.aws.validated
def test_lambda_w_dynamodb_event_filter(deploy_cfn_template, aws_client):
function_name = f"test-fn-{short_uid()}"
Expand Down Expand Up @@ -53,13 +51,11 @@ def _assert_single_lambda_call():
retry(_assert_single_lambda_call, retries=30)


# TODO make a test simular to one above but for updated filtering


@markers.snapshot.skip_snapshot_verify(
[
"$..EventSourceMappings..FunctionArn",
"$..EventSourceMappings..LastProcessingResult",
# TODO: Fix flaky ESM state mismatch upon update in LocalStack (expected Enabled, actual Disabled)
# This might be a parity issue if AWS does rolling updates (i.e., never disables the ESM upon update).
"$..EventSourceMappings..State",
Comment on lines +56 to +58
Copy link
Member

Choose a reason for hiding this comment

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

👍

]
)
@markers.aws.validated
Expand Down Expand Up @@ -261,7 +257,6 @@ def test_lambda_alias(deploy_cfn_template, snapshot, aws_client):
not in_default_partition(), reason="Test not applicable in non-default partitions"
)
@markers.aws.validated
@markers.snapshot.skip_snapshot_verify(paths=["$..DestinationConfig"])
def test_lambda_code_signing_config(deploy_cfn_template, snapshot, account_id, aws_client):
snapshot.add_transformer(snapshot.transform.cloudformation_api())
snapshot.add_transformer(snapshot.transform.lambda_api())
Expand Down Expand Up @@ -305,7 +300,12 @@ def test_event_invoke_config(deploy_cfn_template, snapshot, aws_client):
snapshot.match("event_invoke_config", event_invoke_config)


@markers.snapshot.skip_snapshot_verify(paths=["$..CodeSize"])
@markers.snapshot.skip_snapshot_verify(
paths=[
# Lambda ZIP flaky in CI
Copy link
Member Author

Choose a reason for hiding this comment

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

@dfangl @dominikschubert Is that assumption correct?

Copy link
Member

Choose a reason for hiding this comment

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

Usually yes, we cannot totally rely on this, as it might change.

"$..CodeSize",
]
)
@markers.aws.validated
def test_lambda_version(deploy_cfn_template, snapshot, aws_client):
snapshot.add_transformer(snapshot.transform.cloudformation_api())
Expand Down Expand Up @@ -462,7 +462,6 @@ def test_lambda_vpc(deploy_cfn_template, aws_client):
aws_client.lambda_.invoke(FunctionName=fn_name, LogType="Tail", Payload=b"{}")


@pytest.mark.skip(reason="fails/times out with new provider") # FIXME
@markers.aws.validated
def test_update_lambda_permissions(deploy_cfn_template, aws_client):
stack = deploy_cfn_template(
Expand Down Expand Up @@ -619,16 +618,12 @@ def wait_logs():

@markers.snapshot.skip_snapshot_verify(
paths=[
"$..MaximumRetryAttempts",
"$..ParallelizationFactor",
"$..StateTransitionReason",
# Lambda
"$..Tags",
"$..Configuration.CodeSize",
"$..Configuration.Layers",
"$..Configuration.CodeSize", # Lambda ZIP flaky in CI
# SQS
"$..Attributes.SqsManagedSseEnabled",
# # IAM
# IAM
"$..PolicyNames",
"$..PolicyName",
"$..Role.Description",
Expand Down Expand Up @@ -742,12 +737,8 @@ def wait_logs():
with pytest.raises(aws_client.lambda_.exceptions.ResourceNotFoundException):
aws_client.lambda_.get_event_source_mapping(UUID=esm_id)

# TODO: consider moving into the dedicated DynamoDB => Lambda tests
# TODO: consider moving into the dedicated DynamoDB => Lambda tests because it tests the filtering functionality rather than CloudFormation (just using CF to deploy resources)
# tests.aws.services.lambda_.test_lambda_integration_dynamodbstreams.TestDynamoDBEventSourceMapping.test_dynamodb_event_filter
@pytest.mark.skipif(
config.EVENT_RULE_ENGINE != "java",
reason="Filtering is broken with the Python rule engine for this specific case (exists:false) in ESM v2",
)
@markers.aws.validated
def test_lambda_dynamodb_event_filter(
self, dynamodb_wait_for_table_active, deploy_cfn_template, aws_client, monkeypatch
Expand Down Expand Up @@ -786,8 +777,7 @@ def _send_events():
paths=[
# Lambda
"$..Tags",
"$..Configuration.CodeSize",
"$..Configuration.Layers",
"$..Configuration.CodeSize", # Lambda ZIP flaky in CI
# IAM
"$..PolicyNames",
"$..policies..PolicyName",
Expand All @@ -801,12 +791,6 @@ def _send_events():
"$..Table.Replicas",
# stream result
"$..StreamDescription.CreationRequestDateTime",
# event source mapping
"$..BisectBatchOnFunctionError",
"$..DestinationConfig",
"$..LastProcessingResult",
"$..MaximumRecordAgeInSeconds",
"$..TumblingWindowInSeconds",
]
)
@markers.aws.validated
Expand Down Expand Up @@ -929,16 +913,9 @@ def wait_logs():
paths=[
"$..Role.Description",
"$..Role.MaxSessionDuration",
"$..BisectBatchOnFunctionError",
"$..DestinationConfig",
"$..LastProcessingResult",
"$..MaximumRecordAgeInSeconds",
"$..Configuration.CodeSize",
"$..Tags",
"$..StreamDescription.StreamModeDetails",
"$..Configuration.Layers",
"$..TumblingWindowInSeconds",
# flaky because we currently don't actually wait in cloudformation for it to be active
# TODO: wait for ESM to become active in CloudFormation to mitigate these flaky fields
"$..Configuration.LastUpdateStatus",
"$..Configuration.State",
"$..Configuration.StateReason",
Expand Down Expand Up @@ -1094,11 +1071,11 @@ class TestCfnLambdaDestinations:

"""

@pytest.mark.skip(reason="not supported atm and test needs further work")
@pytest.mark.parametrize(
["on_success", "on_failure"],
[
("sqs", "sqs"),
# TODO: test needs further work
# ("sns", "sns"),
# ("lambda", "lambda"),
# ("eventbridge", "eventbridge")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"tests/aws/services/cloudformation/resources/test_lambda.py::TestCfnLambdaDestinations::test_generic_destination_routing[sqs-sqs]": {
"last_validated_date": "2024-12-10T16:48:04+00:00"
},
"tests/aws/services/cloudformation/resources/test_lambda.py::TestCfnLambdaIntegrations::test_cfn_lambda_dynamodb_source": {
"last_validated_date": "2024-10-12T10:46:17+00:00"
},
Expand Down Expand Up @@ -39,7 +42,7 @@
"last_validated_date": "2024-04-09T07:21:37+00:00"
},
"tests/aws/services/cloudformation/resources/test_lambda.py::test_lambda_w_dynamodb_event_filter_update": {
"last_validated_date": "2024-10-12T10:42:00+00:00"
"last_validated_date": "2024-12-11T09:03:52+00:00"
},
"tests/aws/services/cloudformation/resources/test_lambda.py::test_multiple_lambda_permissions_for_singlefn": {
"last_validated_date": "2024-04-09T07:25:05+00:00"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,12 @@ def _snapshot_transformers(snapshot):

@markers.snapshot.skip_snapshot_verify(
paths=[
# TODO: Fix transformer conflict between shardId and AWS account number (e.g., 000000000000):
# 'shardId-000000000000:<sequence-number:1>' → 'shardId-111111111111:<sequence-number:1>' (expected → actual)
"$..Records..eventID",
"$..BisectBatchOnFunctionError",
"$..DestinationConfig",
"$..LastProcessingResult",
"$..EventSourceMappingArn",
"$..MaximumBatchingWindowInSeconds",
"$..MaximumRecordAgeInSeconds",
"$..ResponseMetadata.HTTPStatusCode",
"$..State",
"$..Topics",
"$..TumblingWindowInSeconds",
# TODO: Fix transformer issue: 'shardId-000000000000' → 'shardId-111111111111' ... (expected → actual)
"$..Messages..Body.KinesisBatchInfo.shardId",
"$..Message.KinesisBatchInfo.shardId",
],
)
class TestKinesisSource:
Expand Down Expand Up @@ -255,10 +250,7 @@ def test_duplicate_event_source_mappings(
StartingPosition="LATEST",
)

# TODO: is this test relevant for the new provider without patching SYNCHRONOUS_KINESIS_EVENTS?
# At least, it is flagged as AWS-validated.
@markers.aws.validated
@pytest.mark.skip(reason="deprecated config that only worked using the legacy provider")
def test_kinesis_event_source_mapping_with_async_invocation(
self,
create_lambda_function,
Expand All @@ -269,6 +261,8 @@ def test_kinesis_event_source_mapping_with_async_invocation(
snapshot,
aws_client,
):
"""Tests that records are processed in sequence when submitting 2 batches with 10 records each
because Kinesis streams ensure strict ordering."""
function_name = f"lambda_func-{short_uid()}"
stream_name = f"test-foobar-{short_uid()}"
num_records_per_batch = 10
Expand Down Expand Up @@ -319,6 +313,8 @@ def _send_and_receive_messages():
invocation_events = retry(_send_and_receive_messages, retries=3)
snapshot.match("invocation_events", invocation_events)

# Processing of the second batch should happen at least 5 seconds after first batch because the Lambda function
# of the first batch waits for 5 seconds.
assert (invocation_events[1]["executionStart"] - invocation_events[0]["executionStart"]) > 5

@markers.aws.validated
Expand Down Expand Up @@ -456,12 +452,6 @@ def _send_and_receive_messages():
aws_client.logs, function_name, expected_num_events=1, retries=10
)

@markers.snapshot.skip_snapshot_verify(
paths=[
"$..Messages..Body.KinesisBatchInfo.shardId",
"$..Messages..Body.KinesisBatchInfo.streamArn",
],
)
@markers.aws.validated
def test_kinesis_event_source_mapping_with_on_failure_destination_config(
self,
Expand Down Expand Up @@ -544,11 +534,8 @@ def verify_failure_received():

@markers.snapshot.skip_snapshot_verify(
paths=[
# FIXME Conflict between shardId and AWS account number when transforming
# i.e "shardId-000000000000" versus AWS Account ID 000000000000
"$..Messages..Body.KinesisBatchInfo.shardId",
"$..Messages..Body.KinesisBatchInfo.streamArn",
"$..Records", # FIXME Figure out why there is an extra log record
# TODO: Figure out why there is an extra log record
"$..Records",
],
)
@markers.aws.validated
Expand Down Expand Up @@ -643,11 +630,6 @@ def verify_failure_received():
snapshot.match("kinesis_records", {"Records": sorted_records})

@markers.aws.validated
@markers.snapshot.skip_snapshot_verify(
paths=[
"$..Messages..Body.KinesisBatchInfo.shardId",
],
)
@pytest.mark.parametrize(
"set_lambda_response",
[
Expand Down Expand Up @@ -746,12 +728,6 @@ def verify_failure_received():
invocation_events = [event for event in events if "Records" in event]
snapshot.match("kinesis_events", invocation_events)

@markers.snapshot.skip_snapshot_verify(
paths=[
"$..Message.KinesisBatchInfo.shardId",
"$..Message.KinesisBatchInfo.streamArn",
],
)
@markers.aws.validated
def test_kinesis_event_source_mapping_with_sns_on_failure_destination_config(
self,
Expand Down Expand Up @@ -859,11 +835,6 @@ def verify_failure_received():
snapshot.match("failure_sns_message", failure_sns_message)

@markers.aws.validated
@markers.snapshot.skip_snapshot_verify(
paths=[
"$..Messages..Body.KinesisBatchInfo.shardId",
],
)
@pytest.mark.parametrize(
"set_lambda_response",
[
Expand Down Expand Up @@ -950,7 +921,8 @@ def _verify_messages_received():
@markers.aws.validated
@markers.snapshot.skip_snapshot_verify(
paths=[
"$..Messages..Body.KinesisBatchInfo.shardId",
# TODO: Fix flaky status 'OK' → 'No records processed' ... (expected → actual)
"$..LastProcessingResult",
],
)
def test_kinesis_empty_provided(
Expand Down Expand Up @@ -1016,18 +988,6 @@ def _verify_invoke():
# TODO: add tests for different edge cases in filtering (e.g. message isn't json => needs to be dropped)
# https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html#filtering-kinesis
class TestKinesisEventFiltering:
@markers.snapshot.skip_snapshot_verify(
paths=[
# Lifecycle updates not yet implemented in ESM v2
"$..LastProcessingResult",
],
)
@markers.snapshot.skip_snapshot_verify(
paths=[
"$..Messages..Body.KinesisBatchInfo.shardId",
"$..Messages..Body.KinesisBatchInfo.streamArn",
],
)
@markers.aws.validated
def test_kinesis_event_filtering_json_pattern(
self,
Expand Down
Loading
Loading