PhoenixKit.AWS.SESv2 (phoenix_kit v1.5.1)

View Source

AWS SES v2 API client for operations not supported by ExAws.

This module provides direct API access to AWS SES v2 features that are not yet available in the ExAws library, enabling infrastructure setup without AWS CLI dependency.

Features

  • Configuration set creation and management
  • Event destination configuration for email tracking
  • Automatic handling of "already exists" scenarios
  • Production-ready error messages

Usage

config = [
  access_key_id: "AKIA...",
  secret_access_key: "...",
  region: "eu-north-1"
]

# Create configuration set
{:ok, name} = SESv2.create_configuration_set("myapp-emailing", config)

# Configure event tracking
:ok = SESv2.create_configuration_set_event_destination(
  "myapp-emailing",
  "email-events-to-sns",
  "arn:aws:sns:eu-north-1:123456:topic",
  config
)

Summary

Functions

create_configuration_set(name, config)

Creates a SES configuration set.

Configuration sets allow you to publish email sending events to Amazon SNS, CloudWatch, or Kinesis Firehose.

Parameters

  • name - Name of the configuration set (string)
  • config - AWS configuration keyword list with:
    • :access_key_id - AWS access key ID
    • :secret_access_key - AWS secret access key
    • :region - AWS region (e.g., "eu-north-1")

Returns

  • {:ok, name} - Configuration set created or already exists
  • {:error, reason} - Failed to create configuration set

Examples

iex> config = [access_key_id: "AKIA...", secret_access_key: "...", region: "eu-north-1"]
iex> SESv2.create_configuration_set("myapp-emailing", config)
{:ok, "myapp-emailing"}

# If configuration set already exists, returns success
iex> SESv2.create_configuration_set("myapp-emailing", config)
{:ok, "myapp-emailing"}

create_configuration_set_event_destination(config_set_name, destination_name, topic_arn, config)

Creates an event destination for a configuration set.

Event destinations define where SES publishes email sending events (send, delivery, bounce, etc.).

Parameters

  • config_set_name - Name of the configuration set
  • destination_name - Name for the event destination (e.g., "email-events-to-sns")
  • topic_arn - SNS topic ARN where events will be published
  • config - AWS configuration keyword list

Returns

  • :ok - Event destination created or already exists
  • {:error, reason} - Failed to create event destination

Events Tracked

The event destination is configured to track all 10 AWS SES email event types:

  • SEND - Email accepted by AWS SES
  • REJECT - Email rejected before sending
  • BOUNCE - Email bounced (hard or soft)
  • COMPLAINT - Recipient marked email as spam
  • DELIVERY - Email successfully delivered
  • OPEN - Recipient opened email (tracking pixel loaded)
  • CLICK - Recipient clicked link in email
  • RENDERING_FAILURE - Email template failed to render
  • DELIVERY_DELAY - Temporary delivery delay occurred
  • SUBSCRIPTION - Recipient updated subscription preferences or unsubscribed

Examples

iex> topic_arn = "arn:aws:sns:eu-north-1:123456:myapp-email-events"
iex> SESv2.create_configuration_set_event_destination(
...>   "myapp-emailing",
...>   "email-events-to-sns",
...>   topic_arn,
...>   config
...> )
:ok