Aws s3 module is not available

hello,

i’m using aws s3 for a project and i get the message that “module ExAws.S3.Upload is not available”. when i call the module on my project “alias ExAws.S3”, S3 is not a suggestion.

my deps:

  defp deps do
    [
      {:phoenix, "~> 1.4.0"},
      {:gettext, "~> 0.11"},
      {:plug_cowboy, "~> 2.0"},
      {:jason, "~> 1.0"},
      {:new_relic_agent, "~> 1.0"},
      {:mktp, in_umbrella: true},
      {:recase, "~> 0.3.0"},
      {:csv, "~> 2.0.0"},
      {:brcpfcnpj, "~> 0.1.0"},
      {:ex_aws, "~> 2.0"},
      {:ex_aws_s3, "~> 2.0"},
      {:poison, "~> 3.0"},
      {:hackney, "~> 1.9"}
    ]
  end

Hi @vyalos, if you type mix deps |grep ex_aws what do you get as output?

hello,

this is what i get:

* ex_aws 2.1.3 (Hex package) (mix)
  locked at 2.1.3 (ex_aws) 26b6f036
* ex_aws_s3 2.0.2 (Hex package) (mix)
  locked at 2.0.2 (ex_aws_s3) c0258bbd

Weird so mix definitely knows about the packages. I’d try doing rm -rf deps _build and then running mix do deps.get, deps.compile. Please copy and paste the output of the deps.get, deps.compile bit.

$ mix deps.get
Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
  brcpfcnpj 0.1.0
  bunt 0.2.0
  bypass 1.0.0
  certifi 2.5.1
  combine 0.10.0
  cowboy 2.6.1
  cowlib 2.7.0
  credo 1.0.0
  csv 2.0.0
  decimal 1.6.0
  ecto 2.2.11
  ex_aws 2.1.3
  ex_aws_s3 2.0.2
  gettext 0.17.0
  hackney 1.15.2
  httpoison 1.3.1
  idna 6.0.0
  jason 1.1.2
  junit_formatter 3.0.0
  metrics 1.0.1
  mime 1.3.1
  mimerl 1.2.0
  new_relic_agent 1.9.5
  new_relic_phoenix 0.2.0
  parallel_stream 1.0.6
  params 2.1.0
  parse_trans 3.3.0
  phoenix 1.4.0
  phoenix_pubsub 1.1.1
  plug 1.7.1
  plug_cowboy 2.0.0
  plug_crypto 1.0.0
  poison 3.1.0
  poolboy 1.5.1
  ranch 1.7.1
  recase 0.3.0
  soap 1.0.1
  ssl_verify_fun 1.1.5
  sweet_xml 0.6.6
  timex 3.6.1
  tzdata 1.0.1
  unicode_util_compat 0.4.1
  xml_builder 2.1.1
* Getting junit_formatter (Hex package)
* Getting jason (Hex package)
* Getting httpoison (Hex package)
* Getting timex (Hex package)
* Getting params (Hex package)
* Getting new_relic_agent (Hex package)
* Getting new_relic_phoenix (Hex package)
* Getting bypass (Hex package)
* Getting credo (Hex package)
* Getting soap (Hex package)
* Getting sweet_xml (Hex package)
* Getting xml_builder (Hex package)
* Getting bunt (Hex package)
* Getting plug (Hex package)
* Getting plug_cowboy (Hex package)
* Getting cowboy (Hex package)
* Getting cowlib (Hex package)
* Getting ranch (Hex package)
* Getting mime (Hex package)
* Getting plug_crypto (Hex package)
* Getting phoenix (Hex package)
* Getting phoenix_pubsub (Hex package)
* Getting ssl_verify_fun (Hex package)
* Getting ecto (Hex package)
* Getting decimal (Hex package)
* Getting poolboy (Hex package)
* Getting combine (Hex package)
* Getting gettext (Hex package)
* Getting tzdata (Hex package)
* Getting hackney (Hex package)
* Getting certifi (Hex package)
* Getting idna (Hex package)
* Getting metrics (Hex package)
* Getting mimerl (Hex package)
* Getting unicode_util_compat (Hex package)
* Getting parse_trans (Hex package)
* Getting recase (Hex package)
* Getting csv (Hex package)
* Getting brcpfcnpj (Hex package)
* Getting ex_aws (Hex package)
* Getting ex_aws_s3 (Hex package)
* Getting poison (Hex package)
* Getting parallel_stream (Hex package)
$ mix deps.compile
===> Compiling parse_trans
===> Compiling mimerl
==> xml_builder
Compiling 3 files (.ex)
Generated xml_builder app
===> Compiling metrics
==> bunt
Compiling 2 files (.ex)
Generated bunt app
===> Compiling unicode_util_compat
===> Compiling idna
==> gettext
Compiling 1 file (.yrl)
Compiling 1 file (.erl)
Compiling 20 files (.ex)
Generated gettext app
warning: found quoted keyword "coveralls" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of Unicode letters, numbers, underscore, and @ do not require quotes
==> recase
Compiling 9 files (.ex)
Generated recase app
===> Compiling ranch
==> poolboy (compile)
Compiled src/poolboy_worker.erl
Compiled src/poolboy_sup.erl
src/poolboy.erl:59: Warning: erlang:get_stacktrace/0: deprecated; use the new try/catch syntax for retrieving the stack backtrace
Compiled src/poolboy.erl
==> decimal
Compiling 1 file (.ex)
Generated decimal app
warning: found quoted keyword "coveralls" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of Unicode letters, numbers, underscore, and @ do not require quotes

==> parallel_stream
Compiling 11 files (.ex)
warning: Stream.chunk/4 is deprecated. Use Stream.chunk_every/4 instead
  lib/parallel_stream/producer.ex:16

Generated parallel_stream app
==> jason
Compiling 8 files (.ex)
Generated jason app
warning: String.strip/1 is deprecated. Use String.trim/1 instead

==> poison
Compiling 4 files (.ex)
warning: Integer.to_char_list/2 is deprecated. Use Integer.to_charlist/2 instead
  lib/poison/encoder.ex:173

Generated poison app
==> ssl_verify_fun
Compiling 7 files (.erl)
Generated ssl_verify_fun app
==> combine
Compiling 6 files (.ex)
Generated combine app

==> csv
Compiling 10 files (.ex)

Generated csv app
===> Compiling certifi
===> Compiling hackney
==> tzdata
Compiling 15 files (.ex)
Generated tzdata app
==> timex
Compiling 58 files (.ex)
Generated timex app

==> brcpfcnpj
Compiling 5 files (.ex)

Generated brcpfcnpj app
==> sweet_xml
Compiling 1 file (.ex)
Generated sweet_xml app
==> ex_aws
Compiling 26 files (.ex)
Generated ex_aws app
==> ex_aws_s3
Compiling 7 files (.ex)
Generated ex_aws_s3 app
==> httpoison
Compiling 3 files (.ex)
Generated httpoison app
==> soap
Compiling 10 files (.ex)
Generated soap app
==> credo
Compiling 180 files (.ex)
Compiling lib/credo/code/sigils.ex (its taking more than 15s)
Generated credo app
==> ecto
Compiling 70 files (.ex)
warning: Inspect.Algebra.surround_many/5 is deprecated. Use Inspect.Algebra.container_doc/6 instead
Found at 3 locations:
  lib/ecto/changeset.ex:2400
  lib/ecto/query/inspect.ex:15
  lib/ecto/query/inspect.ex:29

warning: Map.size/1 is deprecated. Use Kernel.map_size/1 instead
Found at 2 locations:
  lib/ecto/query/builder.ex:44
  lib/ecto/query/builder.ex:53

Generated ecto app
==> params
Compiling 4 files (.ex)
Generated params app
==> phoenix_pubsub
Compiling 13 files (.ex)
Generated phoenix_pubsub app
===> Compiling cowlib
===> Compiling cowboy
==> mime
Compiling 2 files (.ex)
Generated mime app
==> plug_crypto
Compiling 4 files (.ex)
Generated plug_crypto app
==> plug
Compiling 1 file (.erl)
Compiling 38 files (.ex)
warning: System.stacktrace/0 outside of rescue/catch clauses is deprecated. If you want to support only Elixir v1.7+, you must access __STACKTRACE__ inside a rescue/catch. If you want to support earlier Elixir versions, move System.stacktrace/0 inside a rescue/catch
  lib/plug/conn/wrapper_error.ex:23

Generated plug app
==> plug_cowboy
Compiling 5 files (.ex)
Generated plug_cowboy app
==> new_relic_agent
Compiling 68 files (.ex)
Generated new_relic_agent app
==> phoenix
Compiling 67 files (.ex)
warning: redefining @doc attribute previously set at line 216
  lib/phoenix/presence.ex:223: Phoenix.Presence (module)

Generated phoenix app
==> new_relic_phoenix
Compiling 3 files (.ex)
Generated new_relic_phoenix app
==> mktp
warning: the dependency :mktp requires Elixir "~> 1.8.1" but you are running on v1.9.4
Compiling 83 files (.ex)
Generated mktp app

So, it downloaded and compiled. If you try using it and it errors, can you paste the full stacktrace and error?

[error] #PID<0.2260.0> running MyProject.Endpoint (connection #PID<0.2259.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: POST /support/help/attachment
** (exit) an exception was raised:
    ** (Protocol.UndefinedError) protocol String.Chars not implemented for %{} of type Map. This protocol is implemented for the following type(s): Ecto.Date, Ecto.DateTime, Ecto.Time, Decimal, Integer, URI, Version, BitString, Time, DateTime, List, Date, Float, Version.Requirement, Atom, NaiveDateTime
        (elixir) lib/string/chars.ex:3: String.Chars.impl_for!/1
        (elixir) lib/string/chars.ex:22: String.Chars.to_string/1
        (ex_aws) lib/ex_aws/operation/s3.ex:54: ExAws.Operation.ExAws.Operation.S3.add_bucket_to_path/1
        (ex_aws) lib/ex_aws/operation/s3.ex:27: ExAws.Operation.ExAws.Operation.S3.perform/2
        (ex_aws_s3) lib/ex_aws/s3/upload.ex:40: ExAws.S3.Upload.initialize/2
        (ex_aws_s3) lib/ex_aws/s3/upload.ex:81: ExAws.Operation.ExAws.S3.Upload.perform/2
        (ex_aws) lib/ex_aws.ex:61: ExAws.request!/2
        (mktp) lib/Support/support.ex:45: Mktp.Support.Support.help_attachment/2
        (my_project) lib/my_project/controllers/support_controller.ex:39: MyProject.SupportController.help_attachment/2
        (my_project) lib/my_project/controllers/support_controller.ex:1: MyProject.SupportController.action/2
        (my_project) lib/my_project/controllers/support_controller.ex:1: MyProject.SupportController.phoenix_controller_pipeline/2
        (my_project) lib/my_project/endpoint.ex:1: MyProject.Endpoint.instrument/4
        (phoenix) lib/phoenix/router.ex:275: Phoenix.Router.__call__/1
        (my_project) lib/my_project/endpoint.ex:1: MyProject.Endpoint.plug_builder_call/2
        (my_project) lib/plug/debugger.ex:122: MyProject.Endpoint."call (overridable 3)"/2
        (my_project) lib/my_project/endpoint.ex:1: MyProject.Endpoint.call/2
        (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:34: Phoenix.Endpoint.Cowboy2Handler.init/2
        (cowboy) /home/projects/my_project/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
        (cowboy) /home/projects/my_project/deps/cowboy/src/cowboy_stream_h.erl:296: :cowboy_stream_h.execute/3
        (cowboy) /home/projects/my_project/deps/cowboy/src/cowboy_stream_h.erl:274: :cowboy_stream_h.request_process/3

cool, so ex_aws_s3 is there and running, but you’re passing in some kind of invalid information.

Can you show the code you have where you use it?

1 Like

you’re right, i changed my service code and i no longer see the “module not available” message.

i have encountered another problem though, this is my service code today:

    bucket_name = Application.get_env(:ex_aws, :bucket)
    file = filename.path

    file
    |> S3.Upload.stream_file()
    |> S3.upload(bucket_name, file)
    |> ExAws.request!()

my bucket_name returns nil.

when i run Application.get_env(:ex_aws, :bucket) on iex -S mix, it returns nil but it works with Application.get_env(:ex_aws, :access_key_id) and Application.get_env(:ex_aws, :secret_access_key).

iex(21)> Application.get_env(:ex_aws, :access_key_id)
"AKIXXXXXXXXXXXXXXXXXX"
iex(22)> Application.get_env(:ex_aws, :secret_access_key)
"5KXXXXXXXXXXXXXXXXXXX"
iex(23)> Application.get_env(:ex_aws, :bucket)           
nil
config :ex_aws,
  json_codec: Jason,
  access_key_id: "AWS_ACCESS_KEY",
  secret_access_key: "AWS_SECRET_ACCESS_KEY",
  bucket: "s3-elixir-test",
  s3: [
    scheme: "https://",
    region: "sa-east-1",
    host: "s3-sa-east-1.amazonaws.com"
  ]

ExAws.S3.list_buckets() |> ExAws.request!() shows my bucket name.

%{
  body: %{
    buckets: [
      %{creation_date: "2020-04-24T14:09:30.000Z", name: "s3-elixir-test"}
    ],

is there something that i’m missing?

i don’t know if it has any correlation but my console shows this message [warn] ExAws: Received redirect, did you specify the correct region? even though my region is correct.

sorry for the amount of information but i’m stuck, i hope it’s understandable.

thank you.

This is not part of ExAws’s configuration. You need to store the bucket on your own application config.

1 Like

everything is working now.

thank you.

1 Like