Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(warehouse-sources): add six GET tables to the aws_ses source (#86839)

jake sciottoa75c051e1245
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/canonical_descriptions.py
index 5442692ab7f8..25b21cd95c28 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/canonical_descriptions.py
@@ -47,6 +47,49 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"tags": "The tags (keys and values) associated with the configuration set, as JSON.",
},
},
+ "contact_lists": {
+ "description": "Contact lists in the account. A contact list stores contacts and the topics they can subscribe to.",
+ "docs_url": "https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetContactList.html",
+ "columns": {
+ "contact_list_name": "The name of the contact list.",
+ "description": "A description of what the contact list is used for.",
+ "topics": "The interest groups, themes, or labels within the list, with each topic's default subscription status, as JSON.",
+ "created_timestamp": "When the contact list was created.",
+ "last_updated_timestamp": "When the contact list was last updated.",
+ "tags": "The tags (keys and values) associated with the contact list, as JSON.",
+ },
+ },
+ "custom_verification_email_templates": {
+ "description": "Custom verification email templates, used to customize the email SES sends when verifying a new email address.",
+ "docs_url": "https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetCustomVerificationEmailTemplate.html",
+ "columns": {
+ "template_name": "The name of the custom verification email template.",
+ "from_email_address": "The email address that the custom verification email is sent from.",
+ "template_subject": "The subject line of the custom verification email.",
+ "template_content": "The content of the custom verification email, in HTML.",
+ "success_redirection_url": "The URL that the recipient of the verification email is sent to if their address is successfully verified.",
+ "failure_redirection_url": "The URL that the recipient of the verification email is sent to if their address is not successfully verified.",
+ },
+ },
+ "dedicated_ip_pools": {
+ "description": "Dedicated IP pools in the account. A pool groups dedicated IP addresses so configuration sets can send through them.",
+ "docs_url": "https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetDedicatedIpPool.html",
+ "columns": {
+ "pool_name": "The name of the dedicated IP pool.",
+ "dedicated_ip_pool_pool_name": "The name of the dedicated IP pool, as returned by the pool detail call.",
+ "dedicated_ip_pool_scaling_mode": "The type of the pool: STANDARD (warm-up managed by you) or MANAGED (warm-up managed by SES).",
+ },
+ },
+ "dedicated_ips": {
+ "description": "Dedicated IP addresses assigned to the account, with their warm-up progress and pool assignment. Empty for accounts without dedicated IPs.",
+ "docs_url": "https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetDedicatedIps.html",
+ "columns": {
+ "ip": "The dedicated IP address.",
+ "warmup_status": "The warm-up status of the address: IN_PROGRESS, DONE, or NOT_APPLICABLE.",
+ "warmup_percentage": "How far along the warm-up process is. 100 means the address is fully warmed up and ready to use.",
+ "pool_name": "The name of the dedicated IP pool that the address is associated with.",
+ },
+ },
"email_identities": {
"description": "The email identities (domains and addresses) registered with the account, with their DKIM, MAIL FROM, and verification details.",
"docs_url": "https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetEmailIdentity.html",
@@ -78,6 +121,29 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"verification_info_soa_record_serial_number": "The serial number from the domain's SOA record.",
},
},
+ "email_templates": {
+ "description": "Email templates stored in SES, including the subject line and the HTML and plain-text bodies used when sending templated email.",
+ "docs_url": "https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetEmailTemplate.html",
+ "columns": {
+ "template_name": "The name of the template.",
+ "created_timestamp": "When the template was created.",
+ "template_content_subject": "The subject line of the email template.",
+ "template_content_text": "The plain-text body of the email template.",
+ "template_content_html": "The HTML body of the email template.",
+ },
+ },
+ "multi_region_endpoints": {
+ "description": "Multi-region endpoints (global endpoints), which route sending across a primary and a secondary AWS Region.",
+ "docs_url": "https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_ListMultiRegionEndpoints.html",
+ "columns": {
+ "endpoint_name": "The name of the multi-region endpoint (global endpoint).",
+ "endpoint_id": "The ID of the multi-region endpoint (global endpoint).",
+ "status": "The status of the endpoint: CREATING, READY, FAILED, or DELETING.",
+ "regions": "The AWS Regions the multi-region endpoint sends email from, as JSON.",
+ "created_timestamp": "When the multi-region endpoint was created.",
+ "last_updated_timestamp": "When the multi-region endpoint was last updated.",
+ },
+ },
"suppressed_destinations": {
"description": "Email addresses on the account-level suppression list. SES does not attempt delivery to these addresses. Addresses removed from the list upstream are not deleted from this table.",
"docs_url": "https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_ListSuppressedDestinations.html",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/settings.py
index 4a9a0894a70d..6ecafa9c1187 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/settings.py
@@ -28,7 +28,7 @@ class AwsSesEndpointConfig:
# summaries (or bare names), so each item is fetched individually for the full row.
detail_path: str | None = None
# Fan-out: key of the item's name in the list response. `None` when list items are plain
- # name strings (ListConfigurationSets).
+ # name strings (ListConfigurationSets, ListDedicatedIpPools).
item_name_key: str | None = None
# Fan-out: column carrying the item name. Set explicitly on every row because detail
# responses (GetEmailIdentity) do not echo the name back.
@@ -59,6 +59,43 @@ AWS_SES_ENDPOINTS: dict[str, AwsSesEndpointConfig] = {
name_column="configuration_set_name",
timestamp_columns=("reputation_options_last_fresh_start",),
),
+ "contact_lists": AwsSesEndpointConfig(
+ name="contact_lists",
+ path="/v2/email/contact-lists",
+ primary_key=["contact_list_name"],
+ result_key="ContactLists",
+ page_size=100,
+ detail_path="/v2/email/contact-lists/{name}",
+ item_name_key="ContactListName",
+ name_column="contact_list_name",
+ timestamp_columns=("created_timestamp", "last_updated_timestamp"),
+ ),
+ "custom_verification_email_templates": AwsSesEndpointConfig(
+ name="custom_verification_email_templates",
+ path="/v2/email/custom-verification-email-templates",
+ primary_key=["template_name"],
+ result_key="CustomVerificationEmailTemplates",
+ page_size=50,
+ detail_path="/v2/email/custom-verification-email-templates/{name}",
+ item_name_key="TemplateName",
+ name_column="template_name",
+ ),
+ "dedicated_ip_pools": AwsSesEndpointConfig(
+ name="dedicated_ip_pools",
+ path="/v2/email/dedicated-ip-pools",
+ primary_key=["pool_name"],
+ result_key="DedicatedIpPools",
+ page_size=100,
+ detail_path="/v2/email/dedicated-ip-pools/{name}",
+ name_column="pool_name",
+ ),
+ "dedicated_ips": AwsSesEndpointConfig(
+ name="dedicated_ips",
+ path="/v2/email/dedicated-ips",
+ primary_key=["ip"],
+ result_key="DedicatedIps",
+ page_size=100,
+ ),
"email_identities": AwsSesEndpointConfig(
name="email_identities",
path="/v2/email/identities",
@@ -75,6 +112,27 @@ AWS_SES_ENDPOINTS: dict[str, AwsSesEndpointConfig] = {
),
raw_keys=frozenset({"Policies"}),
),
+ "email_templates": AwsSesEndpointConfig(
+ name="email_templates",
+ path="/v2/email/templates",
+ primary_key=["template_name"],
+ result_key="TemplatesMetadata",
+ page_size=100,
+ detail_path="/v2/email/templates/{name}",
+ item_name_key="TemplateName",
+ name_column="template_name",
+ timestamp_columns=("created_timestamp",),
+ ),
+ "multi_region_endpoints": AwsSesEndpointConfig(
+ name="multi_region_endpoints",
+ path="/v2/email/multi-region-endpoints",
+ primary_key=["endpoint_id"],
+ result_key="MultiRegionEndpoints",
+ # ListMultiRegionEndpoints bounds PageSize at 1000 (shape PageSizeV2); the other list
+ # operations take an unbounded MaxItems.
+ page_size=1000,
+ timestamp_columns=("created_timestamp", "last_updated_timestamp"),
+ ),
"suppressed_destinations": AwsSesEndpointConfig(
name="suppressed_destinations",
path="/v2/email/suppression/addresses",
@@ -104,6 +162,12 @@ INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {
ENDPOINT_DESCRIPTIONS: dict[str, str] = {
"account": "Sending status, quota, and reputation enforcement for the connected AWS Region. One row per sync.",
"configuration_sets": "Configuration sets with their tracking, delivery, reputation, sending, and suppression options.",
+ "contact_lists": "Contact lists that store your contacts, with their topics, description, and timestamps.",
+ "custom_verification_email_templates": "Custom verification email templates, with their sender, subject, content, and redirect URLs.",
+ "dedicated_ip_pools": "Dedicated IP pools in the account, with the scaling mode of each pool.",
+ "dedicated_ips": "Dedicated IP addresses assigned to the account, with their warm-up progress and pool assignment.",
"email_identities": "Verified email identities (domains and addresses) with DKIM, MAIL FROM, and verification details.",
+ "email_templates": "Email templates stored in SES, with their subject line and HTML and plain-text bodies.",
+ "multi_region_endpoints": "Multi-region endpoints (global endpoints), with their status and the AWS Regions they route sending to.",
"suppressed_destinations": "Email addresses on the account-level suppression list, with the reason and time they were added.",
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/source.py
index 6d4f7fc7a01d..4d4e91e92eed 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/source.py
@@ -58,7 +58,7 @@ class AwsSesSource(ResumableSource[AwsSesSourceConfig, AwsSesResumeConfig]):
"Amazon SES request failed: SignatureDoesNotMatch": "AWS rejected the request signature. Please re-enter the secret access key.",
"Amazon SES request failed: InvalidSignatureException": "AWS rejected the request signature. If you are using temporary credentials, the session token has expired.",
"Amazon SES request failed: ExpiredTokenException": "The AWS session token has expired. Please reconnect with fresh credentials.",
- "Amazon SES request failed: AccessDeniedException": "These AWS credentials are missing SES read permissions. Grant ses:GetAccount, ses:ListConfigurationSets, ses:GetConfigurationSet, ses:ListEmailIdentities, ses:GetEmailIdentity and ses:ListSuppressedDestinations to the IAM user or role.",
+ "Amazon SES request failed: AccessDeniedException": "These AWS credentials are missing SES read permissions. Grant ses:GetAccount, ses:ListConfigurationSets, ses:GetConfigurationSet, ses:ListEmailIdentities, ses:GetEmailIdentity, ses:ListSuppressedDestinations, ses:ListEmailTemplates, ses:GetEmailTemplate, ses:ListContactLists, ses:GetContactList, ses:ListDedicatedIpPools, ses:GetDedicatedIpPool, ses:GetDedicatedIps, ses:ListCustomVerificationEmailTemplates, ses:GetCustomVerificationEmailTemplate and ses:ListMultiRegionEndpoints to the IAM user or role.",
"Invalid AWS region": "Enter a valid AWS region code like us-east-1.",
"AWS access key ID and secret access key are required": "Enter both an AWS access key ID and a secret access key.",
}
@@ -138,7 +138,7 @@ class AwsSesSource(ResumableSource[AwsSesSourceConfig, AwsSesResumeConfig]):
label="Amazon SES",
caption="""Sync your Amazon SES account data into the PostHog Data warehouse.
-Create an IAM user or role with the `ses:GetAccount`, `ses:ListConfigurationSets`, `ses:GetConfigurationSet`, `ses:ListEmailIdentities`, `ses:GetEmailIdentity` and `ses:ListSuppressedDestinations` permissions, then paste its access key ID and secret access key. Add a session token too if you are using temporary credentials.
+Create an IAM user or role with the `ses:GetAccount`, `ses:ListConfigurationSets`, `ses:GetConfigurationSet`, `ses:ListEmailIdentities`, `ses:GetEmailIdentity`, `ses:ListSuppressedDestinations`, `ses:ListEmailTemplates`, `ses:GetEmailTemplate`, `ses:ListContactLists`, `ses:GetContactList`, `ses:ListDedicatedIpPools`, `ses:GetDedicatedIpPool`, `ses:GetDedicatedIps`, `ses:ListCustomVerificationEmailTemplates`, `ses:GetCustomVerificationEmailTemplate` and `ses:ListMultiRegionEndpoints` permissions, then paste its access key ID and secret access key. Add a session token too if you are using temporary credentials.
SES data is regional, so connect one source per AWS Region you send email from. This source syncs account-level data. Per-message send, bounce, and complaint events are only available through SES event destinations, not the SES API.""",
iconPath="/static/services/aws_ses.png",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/tests/test_aws_ses.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/tests/test_aws_ses.py
index 7f0b2dda9eb2..3629458d5c47 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/tests/test_aws_ses.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/tests/test_aws_ses.py
@@ -404,6 +404,172 @@ class TestGetRows:
assert batches == []
assert manager.cleared is True
+ @pytest.mark.parametrize(
+ "endpoint,responses,expected_row,detail_path",
+ [
+ (
+ "email_templates",
+ [
+ {"TemplatesMetadata": [{"TemplateName": "welcome", "CreatedTimestamp": JAN_2025}]},
+ {
+ "TemplateName": "welcome",
+ "TemplateContent": {"Subject": "Hi!", "Text": "Hello", "Html": "<p>Hello</p>"},
+ },
+ ],
+ {
+ "template_name": "welcome",
+ "created_timestamp": dt.datetime(2025, 1, 1, tzinfo=dt.UTC),
+ "template_content_subject": "Hi!",
+ "template_content_text": "Hello",
+ "template_content_html": "<p>Hello</p>",
+ },
+ "/v2/email/templates/welcome",
+ ),
+ (
+ "contact_lists",
+ [
+ {"ContactLists": [{"ContactListName": "newsletter", "LastUpdatedTimestamp": JAN_2025}]},
+ {
+ "ContactListName": "newsletter",
+ "Description": "Weekly product updates",
+ "Topics": [{"TopicName": "releases", "DefaultSubscriptionStatus": "OPT_IN"}],
+ "CreatedTimestamp": JAN_2025,
+ "LastUpdatedTimestamp": JAN_2025,
+ "Tags": [{"Key": "env", "Value": "prod"}],
+ },
+ ],
+ {
+ "contact_list_name": "newsletter",
+ "description": "Weekly product updates",
+ "topics": [{"TopicName": "releases", "DefaultSubscriptionStatus": "OPT_IN"}],
+ "created_timestamp": dt.datetime(2025, 1, 1, tzinfo=dt.UTC),
+ "last_updated_timestamp": dt.datetime(2025, 1, 1, tzinfo=dt.UTC),
+ "tags": [{"Key": "env", "Value": "prod"}],
+ },
+ "/v2/email/contact-lists/newsletter",
+ ),
+ (
+ "dedicated_ip_pools",
+ [
+ {"DedicatedIpPools": ["marketing-pool"]},
+ {"DedicatedIpPool": {"PoolName": "marketing-pool", "ScalingMode": "MANAGED"}},
+ ],
+ {
+ "pool_name": "marketing-pool",
+ "dedicated_ip_pool_pool_name": "marketing-pool",
+ "dedicated_ip_pool_scaling_mode": "MANAGED",
+ },
+ "/v2/email/dedicated-ip-pools/marketing-pool",
+ ),
+ (
+ "dedicated_ips",
+ [
+ {
+ "DedicatedIps": [
+ {
+ "Ip": "192.0.2.10",
+ "WarmupStatus": "DONE",
+ "WarmupPercentage": 100,
+ "PoolName": "marketing-pool",
+ }
+ ]
+ }
+ ],
+ {
+ "ip": "192.0.2.10",
+ "warmup_status": "DONE",
+ "warmup_percentage": 100,
+ "pool_name": "marketing-pool",
+ },
+ None,
+ ),
+ (
+ "custom_verification_email_templates",
+ [
+ {
+ "CustomVerificationEmailTemplates": [
+ {
+ "TemplateName": "verify-address",
+ "FromEmailAddress": "[email protected]",
+ "TemplateSubject": "Please confirm your address",
+ }
+ ]
+ },
+ {
+ "TemplateName": "verify-address",
+ "FromEmailAddress": "[email protected]",
+ "TemplateSubject": "Please confirm your address",
+ "TemplateContent": "<html>Confirm</html>",
+ "SuccessRedirectionURL": "https://example.com/verified",
+ "FailureRedirectionURL": "https://example.com/failed",
+ },
+ ],
+ {
+ "template_name": "verify-address",
+ "from_email_address": "[email protected]",
+ "template_subject": "Please confirm your address",
+ "template_content": "<html>Confirm</html>",
+ "success_redirection_url": "https://example.com/verified",
+ "failure_redirection_url": "https://example.com/failed",
+ },
+ "/v2/email/custom-verification-email-templates/verify-address",
+ ),
+ (
+ "multi_region_endpoints",
+ [
+ {
+ "MultiRegionEndpoints": [
+ {
+ "EndpointName": "global-sending",
+ "Status": "READY",
+ "EndpointId": "e1a2b3c4",
+ "Regions": ["us-east-1", "eu-west-1"],
+ "CreatedTimestamp": JAN_2025,
+ "LastUpdatedTimestamp": JAN_2025,
+ }
+ ]
+ }
+ ],
+ {
+ "endpoint_name": "global-sending",
+ "status": "READY",
+ "endpoint_id": "e1a2b3c4",
+ "regions": ["us-east-1", "eu-west-1"],
+ "created_timestamp": dt.datetime(2025, 1, 1, tzinfo=dt.UTC),
+ "last_updated_timestamp": dt.datetime(2025, 1, 1, tzinfo=dt.UTC),
+ },
+ None,
+ ),
+ ],
+ )
+ def test_each_new_get_table_yields_rows_carrying_its_primary_key_column(
+ self,
+ endpoint: str,
+ responses: list[dict[str, Any]],
+ expected_row: dict[str, Any],
+ detail_path: Optional[str],
+ ) -> None:
+ batches, send, _ = self._run(responses, endpoint=endpoint)
+
+ assert batches == [[expected_row]]
+ primary_key = AWS_SES_ENDPOINTS[endpoint].primary_key
+ assert primary_key is not None
+ for key_column in primary_key:
+ assert expected_row[key_column]
+ if detail_path is not None:
+ assert send.call_args_list[1][0][3] == detail_path
+
+ def test_an_account_with_no_dedicated_ips_yields_an_empty_table_and_stays_reachable(self) -> None:
+ batches, _, manager = self._run([{"DedicatedIps": []}], endpoint="dedicated_ips")
+
+ assert batches == []
+ assert manager.cleared is True
+
+ with mock.patch.object(aws_ses, "send_request", return_value={"DedicatedIps": []}):
+ assert probe_endpoint_permissions("key", "secret", None, "us-east-1", ["dedicated_ips"]) == {
+ "dedicated_ips": None
+ }
+
class TestValidateCredentials:
def test_missing_credentials_short_circuit_without_a_request(self) -> None:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/tests/test_aws_ses_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/tests/test_aws_ses_source.py
index 9f94be7e63e9..33cfbd97002c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/tests/test_aws_ses_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_ses/tests/test_aws_ses_source.py
@@ -1,3 +1,4 @@
+import re
import datetime as dt
from collections.abc import Iterable
from typing import Any, cast
@@ -75,6 +76,20 @@ class TestAwsSesSource:
def test_transient_aws_failures_keep_retrying(self, observed_error: str) -> None:
assert not any(key in observed_error for key in self.source.get_non_retryable_errors())
+ def test_the_caption_and_the_access_denied_message_grant_the_same_iam_actions(self) -> None:
+ # Both surfaces tell the user which IAM actions to grant; if they diverge, the setup
+ # form and the sync error give contradictory instructions.
+ caption = self.source.get_source_config.caption or ""
+ denied_message = next(
+ message for key, message in self.source.get_non_retryable_errors().items() if "AccessDeniedException" in key
+ )
+ assert denied_message is not None
+
+ caption_actions = set(re.findall(r"ses:[A-Za-z0-9]+", caption))
+ message_actions = set(re.findall(r"ses:[A-Za-z0-9]+", denied_message))
+ assert caption_actions == message_actions
+ assert len(caption_actions) >= 16
+
def test_endpoint_permissions_pass_the_configured_credentials_through(self) -> None:
with mock.patch.object(source_module, "probe_endpoint_permissions", return_value={"account": None}) as probe:
assert self.source.get_endpoint_permissions(self.config, team_id=1, endpoints=["account"]) == {