XUtils

aws

AWS clients for Elixir.


AWS minimum chunk size is 5MB

chunk_size = 5_242_880

Create the multipart request

{:ok, %{ “InitiateMultipartUploadResult” => %{

 "UploadId" => upload_id

} }, _} = AWS.S3.create_multipart_upload(client, bucket, filename, %{})

file = File.read!(filename)

Send the file’s binary in parts

parts = file |> String.codepoints() |> Stream.chunk_every(chunk_size) |> Stream.with_index(1) |> Enum.map(fn {chunk, i} ->

chunk = Enum.join(chunk)

{:ok, nil, %{headers: headers, status_code: 200}} =
  AWS.S3.upload_part(client, bucket, filename, %{
    "Body" => chunk,
    "PartNumber" => i,
    "UploadId" => upload_id
  })

{_, etag} = Enum.find(headers, fn {header, _} -> header == "ETag" end)

%{"ETag" => etag, "PartNumber" => i}

end)

input = %{“CompleteMultipartUpload” => %{“Part” => parts}, “UploadId” => upload_id}

Complete the multipart request

AWS.S3.complete_multipart_upload(aws_client, bucket, filename, input)


You can also list objects in a bucket:

```elixir
# create the client just like the example above
iex> AWS.S3.list_objects_v2(client, "bucket-name-here")

And download a specific object:

# create the client just like the example above
# object key is the "file path" in the S3 bucket
iex> AWS.S3.get_object(client, "bucket-name-here", "object-key-here")

Check all S3 related functions in the docs here.

Remember to check the operation documentation for details: https://docs.aws.amazon.com/

Documentation

Online

Local

  • Run mix docs
  • Open docs/index.html

Note: Arguments, errors and response structure can be found by viewing the model schemas used to generate this module at aws-sdk-go/models/apis/<aws-service>/<version>/.

An example is aws-sdk-go/models/apis/rekognition/2016-06-27/api-2.json. Alternatively you can access the documentation for the service you want at AWS docs page.

Tests

$ mix test

Release

  • Make sure the CHANGELOG.md is up-to-date and reflects the changes for the new version.
  • Bump the version here in the README.md and in mix.exs.
  • Run git tag v$VERSION to tag the version that was just published.
  • Run git push --tags origin master to push tags to Github.
  • Run mix hex.publish to publish the new version.

Articles

  • coming soon...