Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
feat(cloudformation): provision SES configuration sets and event destinations (#1427)
ryan-bennett9b1787ca72b4
diff --git a/README.md b/README.mdindex 06321205..30cfd30f 100644--- a/README.md+++ b/README.md@@ -536,6 +536,8 @@ subnet = ec2.create_subnet(| `AWS::ApiGatewayV2::Integration` | Integration ID | IntegrationId || `AWS::ApiGatewayV2::Route` | Route ID | RouteId || `AWS::SES::EmailIdentity` | Identity | EmailIdentity |+| `AWS::SES::ConfigurationSet` | Configuration set name | Id |+| `AWS::SES::ConfigurationSetEventDestination` | Event destination ID | Id || `AWS::WAFv2::WebACL` | WebACL ID | Arn, Id || `AWS::CloudFront::Distribution` | Distribution ID | Arn, DomainName, Id || `AWS::CloudWatch::Alarm` | Alarm name | Arn |diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.pyindex b92e7a49..68a73eb1 100644--- a/ministack/services/cloudformation/provisioners.py+++ b/ministack/services/cloudformation/provisioners.py@@ -48,6 +48,7 @@ import ministack.services.s3 as _s3import ministack.services.s3tables as _s3tablesimport ministack.services.secretsmanager as _smimport ministack.services.ses as _ses+import ministack.services.ses_v2 as _ses_v2import ministack.services.sns as _snsimport ministack.services.sqs as _sqsimport ministack.services.ssm as _ssm@@ -5195,6 +5196,55 @@ def _ses_email_identity_delete(physical_id, props):_ses._identities.pop(physical_id, None)+# ---------------------------------------------------------------------------+# SES ConfigurationSet+# ---------------------------------------------------------------------------++def _ses_configuration_set_create(logical_id, props, stack_name):+ # AWS::SES::ConfigurationSet Ref returns the configuration set name; when the+ # template omits Name, CloudFormation generates one from the stack/logical id.+ name = props.get("Name") or _physical_name(stack_name, logical_id, max_len=64)+ # Register with both the classic (v1) and v2 SES stores so DescribeConfigurationSet+ # (Query API) and GetConfigurationSet (v2 REST API) both see the set.+ _ses._configuration_sets[name] = {+ "Name": name,+ "CreatedTimestamp": _ses._iso_now(),+ }+ _ses_v2._config_sets[name] = {"ConfigurationSetName": name, "Tags": []}+ return name, {"Id": name}+++def _ses_configuration_set_delete(physical_id, props):+ _ses._configuration_sets.pop(physical_id, None)+ _ses_v2._config_sets.pop(physical_id, None)+++# ---------------------------------------------------------------------------+# SES ConfigurationSetEventDestination+# ---------------------------------------------------------------------------++def _ses_configuration_set_event_destination_create(logical_id, props, stack_name):+ config_set = props.get("ConfigurationSetName", "")+ destination = props.get("EventDestination", {}) or {}+ dest_name = destination.get("Name") or _physical_name(+ stack_name, logical_id, max_len=64)+ # Record the event destination against its configuration set (if present) so+ # the set round-trips with its destinations; the emulator does not deliver+ # SES events, this is CFN provisioning fidelity only.+ record = _ses._configuration_sets.get(config_set)+ if record is not None:+ record.setdefault("EventDestinations", {})[dest_name] = destination+ # The physical id encodes both names so delete can locate the destination.+ return f"{config_set}|{dest_name}", {"Id": dest_name}+++def _ses_configuration_set_event_destination_delete(physical_id, props):+ config_set, _, dest_name = physical_id.partition("|")+ record = _ses._configuration_sets.get(config_set)+ if record is not None:+ record.get("EventDestinations", {}).pop(dest_name, None)++# ---------------------------------------------------------------------------# WAFv2 WebACL# ---------------------------------------------------------------------------@@ -6143,6 +6193,8 @@ _RESOURCE_HANDLERS = {"AWS::ApiGatewayV2::Route": {"create": _apigw_v2_route_create, "delete": _apigw_v2_route_delete},"AWS::ApiGatewayV2::Authorizer": {"create": _apigw_v2_authorizer_create, "update": _apigw_v2_authorizer_update, "delete": _apigw_v2_authorizer_delete},"AWS::SES::EmailIdentity": {"create": _ses_email_identity_create, "delete": _ses_email_identity_delete},+ "AWS::SES::ConfigurationSet": {"create": _ses_configuration_set_create, "delete": _ses_configuration_set_delete},+ "AWS::SES::ConfigurationSetEventDestination": {"create": _ses_configuration_set_event_destination_create, "delete": _ses_configuration_set_event_destination_delete},"AWS::WAFv2::WebACL": {"create": _waf_web_acl_create, "delete": _waf_web_acl_delete},"AWS::CloudFront::CloudFrontOriginAccessIdentity": {"create": _cf_oai_create,diff --git a/tests/test_cfn.py b/tests/test_cfn.pyindex 095625e5..a4ca62ca 100644--- a/tests/test_cfn.py+++ b/tests/test_cfn.py@@ -9153,3 +9153,56 @@ def test_custom_resource_rejects_cross_region_lambda_token(cfn):except Exception:passwest_lam.delete_function(FunctionName=fn_name)+++def test_cfn_ses_configuration_set_and_event_destination(cfn, ses, sesv2):+ cs_name = f"cfn-ses-cs-{_uuid_mod.uuid4().hex[:8]}"+ template = {+ "AWSTemplateFormatVersion": "2010-09-09",+ "Resources": {+ "AlarmTopic": {+ "Type": "AWS::SNS::Topic",+ "Properties": {"TopicName": f"{cs_name}-events"},+ },+ "ConfigSet": {+ "Type": "AWS::SES::ConfigurationSet",+ "Properties": {"Name": cs_name},+ },+ "EventDest": {+ "Type": "AWS::SES::ConfigurationSetEventDestination",+ "Properties": {+ "ConfigurationSetName": {"Ref": "ConfigSet"},+ "EventDestination": {+ "Name": "to-sns",+ "Enabled": True,+ "MatchingEventTypes": ["send", "bounce", "complaint"],+ "SnsDestination": {"TopicARN": {"Ref": "AlarmTopic"}},+ },+ },+ },+ },+ "Outputs": {+ "ConfigSetName": {"Value": {"Ref": "ConfigSet"}},+ },+ }+ cfn.create_stack(StackName="cfn-ses-cs", TemplateBody=json.dumps(template))+ stack = _wait_stack(cfn, "cfn-ses-cs")+ assert stack["StackStatus"] == "CREATE_COMPLETE", stack.get("StackStatusReason")++ # Ref on the configuration set resolves to its name.+ outputs = {o["OutputKey"]: o["OutputValue"] for o in stack.get("Outputs", [])}+ assert outputs["ConfigSetName"] == cs_name++ # The set is visible through both the classic and v2 SES APIs.+ described = ses.describe_configuration_set(ConfigurationSetName=cs_name)+ assert described["ConfigurationSet"]["Name"] == cs_name+ listed = ses.list_configuration_sets()["ConfigurationSets"]+ assert any(cs.get("Name") == cs_name for cs in listed)+ assert sesv2.get_configuration_set(+ ConfigurationSetName=cs_name)["ConfigurationSetName"] == cs_name++ cfn.delete_stack(StackName="cfn-ses-cs")+ _wait_stack(cfn, "cfn-ses-cs")++ with pytest.raises(ClientError):+ ses.describe_configuration_set(ConfigurationSetName=cs_name)