Trying to use AWS QLDB with ex_aws_qldb but running into problems

I am trying to use Amazon AWS QLDB (Quantum Ledger Database) with Phoenix/Elixir and the ex_aws_qldb package and dont’t know exactly how to use ex_aws_qldb functions and types to get it running. It is not clear for me, which functions and types should be used in which order to get the expected results.

What I’ve done so far:

  1. Created the example ledger database “vehicles-registration” with example data in aws and setting a user in AWS IAM with full access to the ledger database
  2. Creating a Phoenix/Elixir project and Installing the ex_aws_qldb package with all the dependencies
  3. Creating a module “Instructions” with a simple function get_vehicles() as a playground to trying out the CRUD szenarios

First of all I tried to get a connection to qldb and to query example data from “vehicles-registration” database in the way but definitely not sure if this is correct:

{:ok, session} =
      ExAws.QLDBSession.start_session("vehicle-registration")
      |> ExAws.request(region: Application.get_env(:mpp, :aws_region))

    {:ok, transaction} =
      ExAws.QLDBSession.start_transaction(session["StartSession"]["SessionToken"])
      |> ExAws.request(region: Application.get_env(:mpp, :aws_region))

    {:ok, executeStatement} =
      ExAws.QLDBSession.execute_statement(
        session["StartSession"]["SessionToken"],
        transaction["StartTransaction"]["TransactionId"],
        "SELECT * FROM Vehicle",
        []
      )
      |> ExAws.request(region: Application.get_env(:mpp, :aws_region))

Actually I got a hashed result back:

{:ok,
 %{
   "ExecuteStatement" => %{
     "FirstPage" => %{
       "Values" => [
         %{
           "IonBinary" => "4AEA6u6mgYPeooe+n4NWSU6EVHlwZYRZZWFyhE1ha2WFTW9kZWyFQ29sb3LeuYqOkTFDNFJKRkFHMEZDNjI1Nzk3i4VTZWRhbowiB+ONiE1lcmNlZGVzjodDTEsgMzUwj4VXaGl0ZQ=="
         },
         %{
           "IonBinary" => "4AEA6u6mgYPeooe+n4NWSU6EVHlwZYRZZWFyhE1ha2WFTW9kZWyFQ29sb3LetYqOkUtNOFNSREhGNkVVMDc0NzYxi4VTZWRhbowiB9+NhVRlc2xhjodNb2RlbCBTj4RCbHVl"
         },
         %{
           "IonBinary" => "4AEA6u6mgYPeooe+n4NWSU6EVHlwZYRZZWFyhE1ha2WFTW9kZWyFQ29sb3LewoqOkTNIR0dLNUc1M0ZNNzYxNzY1i4pNb3RvcmN5Y2xljCIH242GRHVjYXRpjoxNb25zdGVyIDEyMDCPhlllbGxvdw=="
         },
         %{
           "IonBinary" => "4AEA6u6mgYPeooe+n4NWSU6EVHlwZYRZZWFyhE1ha2WFTW9kZWyFQ29sb3LesYqOkTFONEFMMTFENzVDMTA5MTUxi4VTZWRhbowiB9uNhEF1ZGmOgkE1j4ZTaWx2ZXI="
         },
         %{
           "IonBinary" => "4AEA6u6mgYPeooe+n4NWSU6EVHlwZYRZZWFyhE1ha2WFTW9kZWyFQ29sb3LesoqOkTFIVkJCQUFOWFdINTQ0MjM3i4RTZW1pjCIH2Y2ERm9yZI6FRiAxNTCPhUJsYWNr"
         }
       ]
     }
   }
 }}

But now I am confused. How do I get the result in clear text? So I thought, using the commit_function is maybe necessary and did the following:

ExAws.QLDBSession.commit_transaction(
      session["StartSession"]["SessionToken"],
      transaction["StartTransaction"]["TransactionId"],
      "SELECT * FROM Vehicle",
      []
    )
    |> ExAws.request(region: Application.get_env(:mpp, :aws_region))

But then, I got an Erlang/Python error back:

** (ErlangError) Erlang error: {:python, :"builtins.ModuleNotFoundError", 'No module named \'amazon\'', ['  File "/Users/gesslbauer/Documents/Webprojects/mpp/_build/dev/lib/ex_aws_qldb/priv/python/qldb_ionhash.py", line 1, in <module>\n    from amazon.ion.simpleion import loads, dumps\n', '  File "/Users/gesslbauer/Documents/Webprojects/mpp/_build/dev/lib/erlport/priv/python3/erlport/erlang.py", line 225, in _incoming_call\n    f = __import__(mod, {}, {}, [objects[0]])\n', '  File "/Users/gesslbauer/Documents/Webprojects/mpp/_build/dev/lib/erlport/priv/python3/erlport/erlang.py", line 233, in _call_with_error_handler\n    function(*args)\n']}
    (erlport) /Users/gesslbauer/Documents/Webprojects/mpp/deps/erlport/src/erlport.erl:234: :erlport.call/3
    (ex_aws_qldb) lib/ex_aws/qldb_session.ex:125: ExAws.QLDBSession.commit_transaction/4
    (mpp) lib/mpp/instructions.ex:75: Mpp.Instructions.get_vehicles/0

Can anyone help me understanding how to use the ex_aws_qldb functions/types in correct way or is there a anywhere a tutorial I could use?

Thanks a lot.

Environment

  • Elixir 1.9.4
  • ex_aws_with_qldb 2.1.2
  • ex_aws_qldb 0.1.0
  • hackney 1.15.2
1 Like