PhoenixKit.AWS.InfrastructureSetup (phoenix_kit v1.5.1)
View SourceAutomated AWS infrastructure setup for email event handling.
This module creates the complete AWS infrastructure for email event tracking:
- SNS Topic for email events
- SQS Dead Letter Queue (DLQ) for failed messages
- SQS Main Queue with DLQ redrive policy
- SNS to SQS subscription
- SES Configuration Set with event destinations
- All necessary IAM policies
Usage
iex> PhoenixKit.AWS.InfrastructureSetup.run(
...> project_name: "myapp",
...> region: "eu-north-1",
...> access_key_id: "AKIA...",
...> secret_access_key: "..."
...> )
{:ok, %{
"aws_region" => "eu-north-1",
"aws_sns_topic_arn" => "arn:aws:sns:...",
"aws_sqs_queue_url" => "https://sqs...",
...
}}Configuration Options
:project_name- Project name used as prefix for resources (required):region- AWS region (default: "eu-north-1"):access_key_id- AWS access key ID (required):secret_access_key- AWS secret access key (required):queue_visibility_timeout- Main queue visibility timeout in seconds (default: 600 / 10 minutes):queue_retention- Message retention period in seconds (default: 1209600 / 14 days):max_receive_count- Max retries before DLQ (default: 3):polling_interval_ms- SQS polling interval in milliseconds (default: 5000)
Queue Configuration (Optimized for Email Events)
Main Queue:
- Visibility Timeout: 10 minutes - Allows complex database operations without message redelivery
- Message Retention: 14 days - Protects against extended outages (weekends, holidays)
- Max Receive Count: 3 attempts - Balances retry attempts with DLQ routing
Dead Letter Queue:
- Visibility Timeout: 1 minute - For manual processing and troubleshooting
- Message Retention: 14 days - Allows thorough analysis of failed messages
Return Values
{:ok, config_map}- Successfully created infrastructure{:error, step, reason}- Failed at specific step with reason
Summary
Functions
Runs the complete AWS infrastructure setup.
Options
:project_name- Required. Project name for resource naming:region- AWS region (default: "eu-north-1"):access_key_id- AWS access key (falls back to settings/env):secret_access_key- AWS secret key (falls back to settings/env)
Examples
iex> run(project_name: "myapp", region: "eu-north-1")
{:ok, %{"aws_sns_topic_arn" => "arn:aws:sns:...", ...}}
iex> run(project_name: "test")
{:error, "get_account_id", "Invalid credentials"}