envixo
ExAws: HTTP ERROR: :nxdomain for URL: s3.amazonaws.com/logo/original-xx.png ATTEMPT: 10
I have an application in Phoenix 1.6.2 that uploads files to Amazon S3 using ex_aws_s3.
On localhost the upload works fine for the bucket, but in production the upload doesn’t work.
This error happens:
15:49:33.135 [warn] ExAws: HTTP ERROR: :nxdomain for URL: "https:/prd-envixo-bucket.s3.amazonaws.com/1/logo/original-549bac34-7c85-42e6-b2cd-cb3ce7f71fab.png" ATTEMPT: 10
15:49:33.136 [error] GenServer #PID<0.2635.0> terminating
** (ExAws.Error) ExAws Request Error!
{:error, :nxdomain}
(ex_aws 2.2.9) lib/ex_aws.ex:87: ExAws.request!/2
(my_app 0.1.0) lib/my_app_web/live/register_wizard/register_wizard_step2_live.ex:87: anonymous fn/4 in MyAppWeb.RegisterWizardStep2Live.consume_logo/2
(phoenix_live_view 0.17.2) lib/phoenix_live_view/upload_channel.ex:20: Phoenix.LiveView.UploadChannel.consume/3
I’ve tried several different settings, but nothing works.
Looks like the ex_aws_s3 has a bug and generates the wrong URL.
My prod.secret.exs file:
config :ex_aws,
bucket: System.fetch_env!("AWS_BUCKET"),
cloud_front: System.fetch_env!("AWS_CLOUD_FRONT"),
region: System.fetch_env!("AWS_REGION"),
access_key_id: [System.fetch_env!("AWS_ACCESS_KEY_ID"), :instance_role],
secret_access_key: [System.fetch_env!("AWS_SECRET_ACCESS_KEY"), :instance_role]
config :ex_aws, :s3, scheme: "https://"
And this is my code that uploads the file:
@s3_bucket Application.fetch_env!(:ex_aws, :bucket)
defp s3_url, do: "#{@s3_bucket}.s3.amazonaws.com"
def consume_logo(socket, current_enterprise) do
consume_uploaded_entries(socket, :logo, fn meta, entry ->
# Delete old file if exists on S3
if current_enterprise.logo_original_url do
logo_path = file_s3_path(current_enterprise.logo_original_url)
ExAws.S3.delete_object(s3_url(), logo_path) |> ExAws.request!()
end
if current_enterprise.logo_thumbnail_url do
logo_path = file_s3_path(current_enterprise.logo_thumbnail_url)
ExAws.S3.delete_object(s3_url(), logo_path) |> ExAws.request!()
end
# Upload new original file to S3
original_url = Path.join(s3_url(), filename(entry, socket, :original))
{:ok, original_contents} = File.read(meta.path)
ExAws.S3.put_object(s3_url(), file_s3_path(original_url), original_contents) |> ExAws.request!()
# Resize and upload thumbnail file to S3
thumbnail_url = Path.join(s3_url(), filename(entry, socket, :thumbnail))
thumbnail = Image.resize(meta.path, 189, 50)
{:ok, thumbnail_contents} = File.read(thumbnail.path)
ExAws.S3.put_object(s3_url(), file_s3_path(thumbnail_url), thumbnail_contents) |> ExAws.request!()
# Delete temp files
File.rm!(meta.path)
File.rm!(thumbnail.path)
# Return a new url image for original and thumbnail
{original_url, thumbnail_url}
end)
end
defp file_s3_path(file_url) do
file_url |> String.replace("#{s3_url()}/", "")
end
defp filename(entry, socket, type) do
[ext | _] = MIME.extensions(entry.client_type)
"#{socket.assigns.current_enterprise.id}/logo/#{type}-#{entry.uuid}.#{ext}"
end
Does anyone know how I can solve this problem?
Thank you for your help.
Most Liked
al2o3cr
https:/prd-envixo... That lone / seems very sus.
The code in ex_aws_s3 that builds a URL doesn’t add/remove any slashes from the configured value of scheme.
2
Popular in Questions
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
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
Hi,
I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
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
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Other popular topics
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition)
It’s been a while since we first asked this, I...
New
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









