annad

annad

Oban / Swoosh / AmazonSES error after upgrading to Elixir 1.15.4

Hoping someone can point me in the right direction because I’m really stuck…

I switched to AmazonSES and my emails were sending until I upgraded to Elixir 1.15.4. Now I’m getting this Oban error every time I try to send an emails:

{"{\"at\": \"2023-08-29T23:22:06.348323Z\", \"error\": \"** (ArgumentError) construction of binary failed: segment 2 of type 'binary': expected a binary but got: :error\\n    (swoosh 1.11.5) lib/swoosh/adapters/amazon_ses.ex:261: Swoosh.Adapters.AmazonSES.generate_signature/4\\n    (swoosh 1.11.5) lib/swoosh/adapters/amazon_ses.ex:196: Swoosh.Adapters.AmazonSES.prepare_header_authorization/4\\n    (swoosh 1.11.5) lib/swoosh/adapters/amazon_ses.ex:183: Swoosh.Adapters.AmazonSES.prepare_headers/4\\n    (swoosh 1.11.5) lib/swoosh/adapters/amazon_ses.ex:98: Swoosh.Adapters.AmazonSES.deliver/2\\n    (my_app 0.1.0) lib/my_app/mail/mailer.ex:5: anonymous fn/2 in MyApp.Mail.Mailer.instrument/3\\n    (telemetry 1.2.1) /Users/annad/MyApp/App/my_app/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3\\n    (oban 2.15.4) lib/oban/queue/executor.ex:129: Oban.Queue.Executor.perform/1\\n    (oban 2.15.4) lib/oban/queue/executor.ex:74: Oban.Queue.Executor.call/1\\n    (elixir 1.15.4) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2\\n    (elixir 1.15.4) lib/task/supervised.ex:36: Task.Supervised.reply/4\\n\", \"attempt\": 1}"}

At first I thought I was getting this error because Amazon had me in the sandbox. But they freed me from the sandbox and the error kept happening.

I queue mail in Oban (throttling it using snooze), so I thought maybe I got out of sync with Oban releases when I upgraded Elixir. I decided to upgrade all of my apps related to mail, so I’m now on:

      {:phoenix_swoosh, "~> 1.2"},
      {:swoosh, "~> 1.11.5"},
      {:gen_smtp, "~> 1.0"},
      {:hackney, "~> 1.9"},
      {:oban, "~> 2.15.4"},

That didn’t fix it.

I commented out my code except for the part that sends the mail to make sure it’s not my code.

I read this blog post by @ScriptyScott (which was excellent!), so I made the following addition to my config file:

config :swoosh, :api_client, Swoosh.ApiClient.Hackney

That didn’t do anything either. My config for the Swoosh.Adapters.AmazonSES is right out of the setup instructions. And it was working at one point with the new Amazon access keys, so I don’t think that’s the problem.

None of my email attempts are even getting to Amazon, because I’ve checked and it hasn’t processed anything. Based on the error message logged with Oban, it seems like the error must be happening in Swoosh or Oban.

I’m having a really hard time understanding the error message above. Hoping that maybe @sorentwo could help me understand which part of the Oban error message has the failure point.

Does anything jump out at anyone? I’ve honestly run out of things to try. Would appreciate any suggestions for areas to explore.

Most Liked

100phlecs

100phlecs

** (ArgumentError) construction of binary failed: segment 2 of type ‘binary’: expected a binary but got: :error
(swoosh 1.11.5) lib/swoosh/adapters/amazon_ses.ex:261: Swoosh.Adapters.AmazonSES.generate_signature/4
(swoosh 1.11.5) lib/swoosh/adapters/amazon_ses.ex:196: Swoosh.Adapters.AmazonSES.prepare_header_authorization/4

Following the error, it looks like the :secret isn’t being properly set.

https://github.com/swoosh/swoosh/blob/e8cc2cb72866e5dd5d38ac6d797825ca7d68798f/lib/swoosh/adapters/amazon_ses.ex#L196-L196

https://github.com/swoosh/swoosh/blob/e8cc2cb72866e5dd5d38ac6d797825ca7d68798f/lib/swoosh/adapters/amazon_ses.ex#L261-L261

Last Post!

annad

annad

It’s super annoying when you spend hours on a bug that was caused by one tiny character (an exclamation point). Sigh.

Sharing in case anyone else runs into the same problem.

When I switched to Amazon SES and entered the new keys, at some point I accidentally went from System.fetch_env!(“MY_KEY”) to System.fetch_env(“MY_KEY”). I lost the exclamation point by accident. ARG! I only realized it when I switched to System.get_env(“MY_KEY”).

Thank you @100phlecs for putting me on the right track!

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement