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

[FOSS] hot fix and improvement #2207

Merged
merged 25 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2aacd6d
change yaml.load to yaml.safe_load for the security best practice
mingkun2020 Mar 2, 2021
060102c
use yaml_parse for consistant style
mingkun2020 Mar 2, 2021
a6ec11e
Merge branch 'develop' of https://github.com/aws/serverless-applicati…
mingkun2020 Jul 8, 2021
b66e8bb
Merge branch 'develop' of https://github.com/aws/serverless-applicati…
mingkun2020 Jul 9, 2021
8bf03ce
remove pillow library for image comparing, use hash instead
mingkun2020 Jul 9, 2021
ceb3268
make it compatible with py2
mingkun2020 Jul 9, 2021
be3b418
some bug fixes for pipeline failures
mingkun2020 Aug 20, 2021
893735e
Merge branch 'aws:develop' into foss-hot-fix
mingkun2020 Aug 20, 2021
58b00fe
better handling throttling issue
mingkun2020 Sep 9, 2021
b20e646
Merge branch 'foss-hot-fix' of https://github.com/mingkun2020/serverl…
mingkun2020 Sep 9, 2021
975bc06
add companion stack for testing
mingkun2020 Sep 17, 2021
b79e69f
add companion stack
mingkun2020 Sep 17, 2021
26cd2f6
add companion stack exist check
mingkun2020 Sep 30, 2021
3c15955
add stack prefix
mingkun2020 Oct 29, 2021
b1fff6f
update runtime
mingkun2020 Nov 4, 2021
bd15f33
Merge branch 'develop' into foss-hot-fix
mingkun2020 Nov 4, 2021
092d4e4
avoid deleting companion stack while prefix is provided
mingkun2020 Nov 23, 2021
8fe45ba
fix some throttling issues
mingkun2020 Nov 23, 2021
7b8e008
move service name to constants, addressed comments
mingkun2020 Nov 25, 2021
3f82302
add service name constant file
mingkun2020 Nov 25, 2021
53474cf
remove unused testing lines
mingkun2020 Nov 25, 2021
5330727
fix error
mingkun2020 Nov 25, 2021
a4c1da6
pass schedule name as parameter
mingkun2020 Nov 25, 2021
a35def2
black reformat
mingkun2020 Nov 25, 2021
aeeb334
remove unused imort
mingkun2020 Nov 25, 2021
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
5 changes: 5 additions & 0 deletions integration/combination/test_api_with_authorizers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from unittest.case import skipIf

import requests

from integration.helpers.base_test import BaseTest
from integration.helpers.deployer.utils.retry import retry
from integration.helpers.exception import StatusCodeError
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import COGNITO


@skipIf(current_region_does_not_support([COGNITO]), "Cognito is not supported in this testing region")
class TestApiWithAuthorizers(BaseTest):
def test_authorizers_min(self):
self.create_and_verify_stack("combination/api_with_authorizers_min")
Expand Down
7 changes: 7 additions & 0 deletions integration/combination/test_api_with_gateway_responses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import GATEWAY_RESPONSES


@skipIf(
current_region_does_not_support([GATEWAY_RESPONSES]), "GatewayResponses is not supported in this testing region"
)
class TestApiWithGatewayResponses(BaseTest):
def test_gateway_responses(self):
self.create_and_verify_stack("combination/api_with_gateway_responses")
Expand Down
5 changes: 5 additions & 0 deletions integration/combination/test_api_with_usage_plan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import USAGE_PLANS


@skipIf(current_region_does_not_support([USAGE_PLANS]), "UsagePlans is not supported in this testing region")
class TestApiWithUsagePlan(BaseTest):
def test_api_with_usage_plans(self):
self.create_and_verify_stack("combination/api_with_usage_plan")
Expand Down
7 changes: 4 additions & 3 deletions integration/combination/test_function_with_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ def test_function_with_alias_with_intrinsics(self):
# Let's change Key by updating the template parameter, but keep template same
# This should create a new version and leave existing version intact
parameters[1]["ParameterValue"] = "code2.zip"
self.deploy_stack(parameters)
# self.deploy_stack(parameters)
self.update_stack("combination/function_with_alias_intrinsics", parameters)
version_ids = get_function_versions(function_name, self.client_provider.lambda_client)
self.assertEqual(["1", "2"], version_ids)

self.assertEqual(["1"], version_ids)
alias = self.get_alias(function_name, alias_name)
self.assertEqual("2", alias["FunctionVersion"])
self.assertEqual("1", alias["FunctionVersion"])

def test_alias_in_globals_with_overrides(self):
# It is good enough if we can create a stack. Globals are pre-processed on the SAM template and don't
Expand Down
14 changes: 11 additions & 3 deletions integration/combination/test_function_with_all_event_types.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support, generate_suffix
from integration.config.service_names import IOT, SCHEDULE_EVENT


@skipIf(
current_region_does_not_support([IOT, SCHEDULE_EVENT]),
"IoT, ScheduleEvent is not supported in this testing region",
)
class TestFunctionWithAllEventTypes(BaseTest):
def test_function_with_all_event_types(self):
self.create_and_verify_stack("combination/function_with_all_event_types")
schedule_name = "TestSchedule" + generate_suffix()
parameters = [self.generate_parameter("ScheduleName", schedule_name)]

stack_outputs = self.get_stack_outputs()
self.create_and_verify_stack("combination/function_with_all_event_types", parameters)

# make sure bucket notification configurations are added
s3_client = self.client_provider.s3_client
Expand All @@ -30,7 +39,6 @@ def test_function_with_all_event_types(self):
self.assertEqual(len(rule_names), 2)

# make sure cloudwatch Schedule event has properties: name, state and description
schedule_name = stack_outputs["ScheduleName"]
cw_rule_result = cloudwatch_events_client.describe_rule(Name=schedule_name)

self.assertEqual(cw_rule_result["Name"], schedule_name)
Expand Down
24 changes: 23 additions & 1 deletion integration/combination/test_function_with_application.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from unittest.case import skipIf

from botocore.exceptions import ClientError

from integration.helpers.base_test import BaseTest
from integration.helpers.deployer.exceptions.exceptions import ThrottlingError
from integration.helpers.deployer.utils.retry import retry_with_exponential_backoff_and_jitter
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import SERVERLESS_REPO


class TestFunctionWithApplication(BaseTest):
@skipIf(
current_region_does_not_support([SERVERLESS_REPO]), "ServerlessRepo is not supported in this testing region"
)
def test_function_referencing_outputs_from_application(self):
self.create_and_verify_stack("combination/function_with_application")

Expand All @@ -11,7 +22,18 @@ def test_function_referencing_outputs_from_application(self):
cfn_client = self.client_provider.cfn_client

function_config = lambda_client.get_function_configuration(FunctionName=lambda_function_name)
stack_result = cfn_client.describe_stacks(StackName=nested_stack_name)
stack_result = self._describe_stacks(cfn_client, nested_stack_name)
expected = stack_result["Stacks"][0]["Outputs"][0]["OutputValue"]

self.assertEqual(function_config["Environment"]["Variables"]["TABLE_NAME"], expected)

@retry_with_exponential_backoff_and_jitter(ThrottlingError, 5, 360)
def _describe_stacks(self, cfn_client, stack_name):
try:
stack_result = cfn_client.describe_stacks(StackName=stack_name)
except ClientError as ex:
if "Throttling" in str(ex):
raise ThrottlingError(stack_name=stack_name, msg=str(ex))
raise ex

return stack_result
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import CWE_CWS_DLQ


@skipIf(current_region_does_not_support([CWE_CWS_DLQ]), "CweCwsDlq is not supported in this testing region")
class TestFunctionWithCweDlqAndRetryPolicy(BaseTest):
def test_function_with_cwe(self):
# Verifying that following resources were created is correct
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import json
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import first_item_in_dict
from integration.helpers.resource import first_item_in_dict, current_region_does_not_support
from integration.config.service_names import CWE_CWS_DLQ


@skipIf(current_region_does_not_support([CWE_CWS_DLQ]), "CweCwsDlq is not supported in this testing region")
class TestFunctionWithCweDlqGenerated(BaseTest):
def test_function_with_cwe(self):
# Verifying that following resources were created is correct
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import CODE_DEPLOY

CODEDEPLOY_APPLICATION_LOGICAL_ID = "ServerlessDeploymentApplication"
LAMBDA_FUNCTION_NAME = "MyLambdaFunction"
LAMBDA_ALIAS = "Live"


@skipIf(current_region_does_not_support([CODE_DEPLOY]), "CodeDeploy is not supported in this testing region")
class TestFunctionWithDeploymentPreference(BaseTest):
def test_lambda_function_with_deployment_preference_uses_code_deploy(self):
self.create_and_verify_stack("combination/function_with_deployment_basic")
Expand Down Expand Up @@ -97,7 +102,9 @@ def _get_deployment_groups(self, application_name):
]

def _get_deployments(self, application_name, deployment_group):
deployments = self.client_provider.code_deploy_client.list_deployments()["deployments"]
deployments = self.client_provider.code_deploy_client.list_deployments(
applicationName=application_name, deploymentGroupName=deployment_group
)["deployments"]
Copy link
Contributor

Choose a reason for hiding this comment

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

For client responses like this are we catching any possible client errors? Also if the client returned a None response due to some error ["deployments"] would also be error prone? (Maybe get("deployments") would be a better option

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it returns a None, it will break and the test will failed as expected(it shouldn't be none).

deployment_infos = [self._get_deployment_info(deployment_id) for deployment_id in deployments]
return deployment_infos

Expand Down
5 changes: 5 additions & 0 deletions integration/combination/test_function_with_dynamoDB.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import DYNAMO_DB


@skipIf(current_region_does_not_support([DYNAMO_DB]), "DynamoDB is not supported in this testing region")
class TestFunctionWithDynamoDB(BaseTest):
def test_function_with_dynamoDB_trigger(self):
self.create_and_verify_stack("combination/function_with_dynamodb")
Expand Down
5 changes: 5 additions & 0 deletions integration/combination/test_function_with_http_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import HTTP_API


@skipIf(current_region_does_not_support([HTTP_API]), "HttpApi is not supported in this testing region")
class TestFunctionWithHttpApi(BaseTest):
def test_function_with_http_api(self):
self.create_and_verify_stack("combination/function_with_http_api")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import HTTP_API


@skipIf(current_region_does_not_support([HTTP_API]), "HttpApi is not supported in this testing region")
class TestFunctionWithImplicitHttpApi(BaseTest):
def test_function_with_implicit_api(self):
self.create_and_verify_stack("combination/function_with_implicit_http_api")
Expand Down
5 changes: 5 additions & 0 deletions integration/combination/test_function_with_kinesis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import KINESIS


@skipIf(current_region_does_not_support([KINESIS]), "Kinesis is not supported in this testing region")
class TestFunctionWithKinesis(BaseTest):
def test_function_with_kinesis_trigger(self):
self.create_and_verify_stack("combination/function_with_kinesis")
Expand Down
5 changes: 5 additions & 0 deletions integration/combination/test_function_with_layers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import LAYERS


@skipIf(current_region_does_not_support([LAYERS]), "Layers is not supported in this testing region")
class TestFunctionWithLayers(BaseTest):
def test_function_with_layer(self):
self.create_and_verify_stack("combination/function_with_layer")
Expand Down
37 changes: 33 additions & 4 deletions integration/combination/test_function_with_mq.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
from unittest.case import skipIf

import pytest
from parameterized import parameterized

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support, generate_suffix
from integration.config.service_names import MQ


@skipIf(current_region_does_not_support([MQ]), "MQ is not supported in this testing region")
class TestFunctionWithMq(BaseTest):
@pytest.fixture(autouse=True)
def companion_stack_outputs(self, get_companion_stack_outputs):
self.companion_stack_outputs = get_companion_stack_outputs

@parameterized.expand(
[
"combination/function_with_mq",
"combination/function_with_mq_using_autogen_role",
("combination/function_with_mq", "MQBrokerName", "MQBrokerUserSecretName", "PreCreatedSubnetOne"),
(
"combination/function_with_mq_using_autogen_role",
"MQBrokerName2",
"MQBrokerUserSecretName2",
"PreCreatedSubnetTwo",
),
]
)
def test_function_with_mq(self, file_name):
self.create_and_verify_stack(file_name)
def test_function_with_mq(self, file_name, mq_broker, mq_secret, subnet_key):
companion_stack_outputs = self.companion_stack_outputs
parameters = self.get_parameters(companion_stack_outputs, subnet_key)
secret_name = mq_secret + "-" + generate_suffix()
parameters.append(self.generate_parameter(mq_secret, secret_name))
secret_name = mq_broker + "-" + generate_suffix()
parameters.append(self.generate_parameter(mq_broker, secret_name))

self.create_and_verify_stack(file_name, parameters)

mq_client = self.client_provider.mq_client
mq_broker_id = self.get_physical_id_by_type("AWS::AmazonMQ::Broker")
Expand All @@ -32,6 +54,13 @@ def test_function_with_mq(self, file_name):
self.assertEqual(event_source_mapping_function_arn, lambda_function_arn)
self.assertEqual(event_source_mapping_mq_broker_arn, mq_broker_arn)

def get_parameters(self, dictionary, subnet_key):
parameters = []
parameters.append(self.generate_parameter("PreCreatedVpc", dictionary["PreCreatedVpc"]))
parameters.append(self.generate_parameter(subnet_key, dictionary[subnet_key]))
parameters.append(self.generate_parameter("PreCreatedInternetGateway", dictionary["PreCreatedInternetGateway"]))
return parameters


def get_broker_summary(mq_broker_id, mq_client):
broker_summaries = mq_client.list_brokers()["BrokerSummaries"]
Expand Down
33 changes: 29 additions & 4 deletions integration/combination/test_function_with_msk.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
from unittest.case import skipIf

import pytest

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support, generate_suffix
from integration.config.service_names import MSK


@skipIf(current_region_does_not_support([MSK]), "MSK is not supported in this testing region")
class TestFunctionWithMsk(BaseTest):
@pytest.fixture(autouse=True)
def companion_stack_outputs(self, get_companion_stack_outputs):
self.companion_stack_outputs = get_companion_stack_outputs

def test_function_with_msk_trigger(self):
self._common_validations_for_MSK("combination/function_with_msk")
companion_stack_outputs = self.companion_stack_outputs
parameters = self.get_parameters(companion_stack_outputs)
cluster_name = "MskCluster-" + generate_suffix()
parameters.append(self.generate_parameter("MskClusterName", cluster_name))
self._common_validations_for_MSK("combination/function_with_msk", parameters)

def test_function_with_msk_trigger_using_manage_policy(self):
self._common_validations_for_MSK("combination/function_with_msk_using_managed_policy")
companion_stack_outputs = self.companion_stack_outputs
parameters = self.get_parameters(companion_stack_outputs)
cluster_name = "MskCluster2-" + generate_suffix()
parameters.append(self.generate_parameter("MskClusterName2", cluster_name))
self._common_validations_for_MSK("combination/function_with_msk_using_managed_policy", parameters)

def _common_validations_for_MSK(self, file_name):
self.create_and_verify_stack(file_name)
def _common_validations_for_MSK(self, file_name, parameters):
self.create_and_verify_stack(file_name, parameters)

kafka_client = self.client_provider.kafka_client

Expand All @@ -32,3 +51,9 @@ def _common_validations_for_MSK(self, file_name):

self.assertEqual(event_source_mapping_function_arn, lambda_function_arn)
self.assertEqual(event_source_mapping_kafka_cluster_arn, msk_cluster_arn)

def get_parameters(self, dictionary):
parameters = []
parameters.append(self.generate_parameter("PreCreatedSubnetOne", dictionary["PreCreatedSubnetOne"]))
parameters.append(self.generate_parameter("PreCreatedSubnetTwo", dictionary["PreCreatedSubnetTwo"]))
return parameters
11 changes: 8 additions & 3 deletions integration/combination/test_function_with_schedule.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support, generate_suffix
from integration.config.service_names import SCHEDULE_EVENT


@skipIf(current_region_does_not_support([SCHEDULE_EVENT]), "ScheduleEvent is not supported in this testing region")
class TestFunctionWithSchedule(BaseTest):
def test_function_with_schedule(self):
self.create_and_verify_stack("combination/function_with_schedule")
schedule_name = "TestSchedule" + generate_suffix()
parameters = [self.generate_parameter("ScheduleName", schedule_name)]

stack_outputs = self.get_stack_outputs()
self.create_and_verify_stack("combination/function_with_schedule", parameters)

cloud_watch_events_client = self.client_provider.cloudwatch_event_client

# get the cloudwatch schedule rule
schedule_name = stack_outputs["ScheduleName"]
cw_rule_result = cloud_watch_events_client.describe_rule(Name=schedule_name)

# checking if the name, description and state properties are correct
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import CWE_CWS_DLQ


@skipIf(current_region_does_not_support([CWE_CWS_DLQ]), "CweCwsDlq is not supported in this testing region")
class TestFunctionWithScheduleDlqAndRetryPolicy(BaseTest):
def test_function_with_schedule(self):
self.create_and_verify_stack("combination/function_with_schedule_dlq_and_retry_policy")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from unittest.case import skipIf

from integration.helpers.base_test import BaseTest
from integration.helpers.common_api import get_queue_policy
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import CWE_CWS_DLQ


@skipIf(current_region_does_not_support([CWE_CWS_DLQ]), "CweCwsDlq is not supported in this testing region")
class TestFunctionWithScheduleDlqGenerated(BaseTest):
def test_function_with_schedule(self):
self.create_and_verify_stack("combination/function_with_schedule_dlq_generated")
Expand Down
Loading