Listing S3 objects with Elixir

Using ExAWS library & Elixir to interact with S3

Published on · 1 min read · 1 view · 1 reading right now

ELIXIR
AWS

Using ExAWS library to interact with AWS S3. The setup steps is given in the library's documentation.

It returns a map with all the objects listed. Used Jason to convert the returned map to JSON data. You can also loop through the contents using Enum.map.

defmodule ElixirS3 do
  def list_objects() do
    {:ok, data} = ExAws.S3.list_objects("links-data") |> ExAws.request()

    jsonData =
      data.body.contents
      |> Enum.map(fn x -> %{key: x.key} end) # Just getting the `key` from objects
      |> Jason.encode!()

    File.write!("./data.json", jsonData)
  end
end

ElixirS3.list_objects()

There's also aws-elixir library to work with AWS.

0 likes

Other articles