|
| 1 | +from time import sleep |
| 2 | +from parameterized import parameterized |
| 3 | +from integration.conftest import clean_bucket |
| 4 | +from integration.helpers.base_test import S3_BUCKET_PREFIX, BaseTest |
| 5 | +from integration.helpers.resource import generate_suffix |
| 6 | + |
| 7 | + |
| 8 | +class TestConnectors(BaseTest): |
| 9 | + def tearDown(self): |
| 10 | + # Some tests will create items in S3 Bucket, which result in stack DELETE_FAILED state |
| 11 | + # manually empty the bucket to allow stacks to be deleted successfully. |
| 12 | + bucket_name = self.get_physical_id_by_type("AWS::S3::Bucket") |
| 13 | + if bucket_name: |
| 14 | + clean_bucket(bucket_name, self.client_provider.s3_client) |
| 15 | + super().tearDown() |
| 16 | + |
| 17 | + @parameterized.expand( |
| 18 | + [ |
| 19 | + ("combination/connector_function_to_function",), |
| 20 | + ("combination/connector_restapi_to_function",), |
| 21 | + ("combination/connector_httpapi_to_function",), |
| 22 | + ("combination/connector_function_to_bucket_read",), |
| 23 | + ("combination/connector_function_to_bucket_write",), |
| 24 | + ("combination/connector_function_to_table_read",), |
| 25 | + ("combination/connector_function_to_table_write",), |
| 26 | + ("combination/connector_function_to_sfn_read",), |
| 27 | + ("combination/connector_function_to_sfn_write",), |
| 28 | + ("combination/connector_function_to_queue_write",), |
| 29 | + ("combination/connector_function_to_queue_read",), |
| 30 | + ("combination/connector_function_to_topic_write",), |
| 31 | + ("combination/connector_function_to_eventbus_write",), |
| 32 | + ("combination/connector_topic_to_queue_write",), |
| 33 | + ("combination/connector_event_rule_to_sqs_write",), |
| 34 | + ("combination/connector_event_rule_to_sns_write",), |
| 35 | + ("combination/connector_event_rule_to_sfn_write",), |
| 36 | + ("combination/connector_event_rule_to_eb_default_write",), |
| 37 | + ("combination/connector_event_rule_to_eb_custom_write",), |
| 38 | + ("combination/connector_event_rule_to_lambda_write",), |
| 39 | + ("combination/connector_sqs_to_function",), |
| 40 | + ("combination/connector_sns_to_function_write",), |
| 41 | + ("combination/connector_table_to_function_read",), |
| 42 | + ] |
| 43 | + ) |
| 44 | + def test_connector_by_invoking_a_function(self, template_file_path): |
| 45 | + self.skip_using_service_detector(template_file_path) |
| 46 | + self.create_and_verify_stack(template_file_path) |
| 47 | + |
| 48 | + lambda_function_name = self.get_physical_id_by_logical_id("TriggerFunction") |
| 49 | + lambda_client = self.client_provider.lambda_client |
| 50 | + s3_client = self.client_provider.s3_client |
| 51 | + |
| 52 | + request_params = { |
| 53 | + "FunctionName": lambda_function_name, |
| 54 | + "InvocationType": "RequestResponse", |
| 55 | + "Payload": "{}", |
| 56 | + } |
| 57 | + response = lambda_client.invoke(**request_params) |
| 58 | + self.assertEqual(response.get("StatusCode"), 200) |
| 59 | + self.assertEqual(response.get("FunctionError"), None) |
| 60 | + |
| 61 | + @parameterized.expand( |
| 62 | + [ |
| 63 | + ("combination/connector_sfn_to_table_read",), |
| 64 | + ("combination/connector_sfn_to_table_write",), |
| 65 | + ("combination/connector_sfn_to_sqs_write",), |
| 66 | + ("combination/connector_sfn_to_sns_write",), |
| 67 | + ("combination/connector_sfn_to_function_write",), |
| 68 | + ("combination/connector_sfn_to_bucket_write",), |
| 69 | + ("combination/connector_sfn_to_bucket_read",), |
| 70 | + ("combination/connector_sfn_to_sfn_async",), |
| 71 | + ("combination/connector_sfn_to_eb_default_write",), |
| 72 | + ("combination/connector_sfn_to_eb_custom_write",), |
| 73 | + ] |
| 74 | + ) |
| 75 | + def test_connector_by_sync_execute_an_state_machine(self, template_file_path): |
| 76 | + self.skip_using_service_detector(template_file_path) |
| 77 | + self.create_and_verify_stack(template_file_path) |
| 78 | + |
| 79 | + state_machine_arn = self.get_physical_id_by_logical_id("TriggerStateMachine") |
| 80 | + sfn_client = self.client_provider.sfn_client |
| 81 | + s3_client = self.client_provider.s3_client |
| 82 | + |
| 83 | + response = sfn_client.start_sync_execution( |
| 84 | + stateMachineArn=state_machine_arn, |
| 85 | + ) |
| 86 | + # Without permission, it will be "FAILED" |
| 87 | + self.assertEqual(response.get("status"), "SUCCEEDED") |
| 88 | + |
| 89 | + @parameterized.expand( |
| 90 | + [ |
| 91 | + ("combination/connector_sfn_to_sfn_sync",), |
| 92 | + ] |
| 93 | + ) |
| 94 | + def test_connector_by_async_execute_an_state_machine(self, template_file_path): |
| 95 | + self.skip_using_service_detector(template_file_path) |
| 96 | + self.create_and_verify_stack(template_file_path) |
| 97 | + |
| 98 | + state_machine_arn = self.get_physical_id_by_logical_id("TriggerStateMachine") |
| 99 | + sfn_client = self.client_provider.sfn_client |
| 100 | + |
| 101 | + response = sfn_client.start_execution( |
| 102 | + stateMachineArn=state_machine_arn, |
| 103 | + ) |
| 104 | + execution_arn = response["executionArn"] |
| 105 | + |
| 106 | + status = None |
| 107 | + wait_tries = 5 |
| 108 | + while wait_tries > 0: |
| 109 | + response = sfn_client.describe_execution(executionArn=execution_arn) |
| 110 | + status = response["status"] |
| 111 | + if status == "RUNNING": |
| 112 | + wait_tries -= 1 |
| 113 | + sleep(5) |
| 114 | + continue |
| 115 | + else: |
| 116 | + break |
| 117 | + |
| 118 | + # Without permission, it will be "FAILED" |
| 119 | + self.assertEqual(status, "SUCCEEDED") |
| 120 | + |
| 121 | + @parameterized.expand( |
| 122 | + [ |
| 123 | + ("combination/connector_bucket_to_function_write",), |
| 124 | + ] |
| 125 | + ) |
| 126 | + def test_connector_by_execute_a_s3_bucket(self, template_file_path): |
| 127 | + self.skip_using_service_detector(template_file_path) |
| 128 | + bucket_name = S3_BUCKET_PREFIX + "connector" + generate_suffix() |
| 129 | + self.create_and_verify_stack( |
| 130 | + template_file_path, [{"ParameterKey": "BucketName", "ParameterValue": bucket_name}] |
| 131 | + ) |
| 132 | + |
| 133 | + lambda_function_name = self.get_physical_id_by_logical_id("TriggerFunction") |
| 134 | + lambda_client = self.client_provider.lambda_client |
| 135 | + s3_client = self.client_provider.s3_client |
| 136 | + |
| 137 | + request_params = { |
| 138 | + "FunctionName": lambda_function_name, |
| 139 | + "InvocationType": "RequestResponse", |
| 140 | + "Payload": "{}", |
| 141 | + } |
| 142 | + response = lambda_client.invoke(**request_params) |
| 143 | + self.assertEqual(response.get("StatusCode"), 200) |
| 144 | + self.assertEqual(response.get("FunctionError"), None) |
0 commit comments