Listing S3 objects with Elixir

Using ExAWS library & Elixir to interact with S3

Published on October 03, 2022 · 1 min read · 0 reading right now · 1 views

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

Comments

1 online · 0 visits
Nothing playing at the moment

Theme: