Coder Social home page Coder Social logo

Comments (5)

ceolinrenato avatar ceolinrenato commented on August 18, 2024 1

Working example of how to get presigned url to download a s3 object (using the changes in the PR)

  def signed_uri(reference, ttl) do
    %{
      remote_storage_bucket: remote_storage_bucket,
      access_key_id: access_key_id,
      remote_storage_region: remote_storage_region
    } = aws_config()

    uri =
      URI.parse(
        "https://#{remote_storage_bucket}.s3.#{remote_storage_region}.#{aws_client().endpoint}/#{AWS.Util.encode_uri(reference, true)}"
      )

    now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
    long_date = NaiveDateTime.to_iso8601(now, :basic) <> "Z"
    short_date = Date.to_iso8601(now, :basic)

    query_params = [
      {"X-Amz-Expires", Integer.to_string(ttl)},
      {"X-Amz-Algorithm", "AWS4-HMAC-SHA256"},
      {"X-Amz-Credential",
       "#{access_key_id}/#{short_date}/#{remote_storage_region}/s3/aws4_request"},
      {"X-Amz-SignedHeaders", "host"},
      {"X-Amz-Date", long_date}
    ]

    url = URI.to_string(%{uri | query: URI.encode_query(query_params)})

    signature_tuple =
      %{aws_client() | service: "s3"}
      |> AWS.Signature.sign_v4_query(now, :get, url, [{"Host", uri.host}], nil)
      |> Enum.find(fn {key, _value} -> key == "X-Amz-Signature" end)

    URI.to_string(%{
      uri
      | query: URI.encode_query([signature_tuple | query_params])
    })
  end

from aws-elixir.

ceolinrenato avatar ceolinrenato commented on August 18, 2024 1

Thanks for maintaining this lib @philss, Wish I knew some erlang to help on the aws-beam/aws_signature side

from aws-elixir.

ceolinrenato avatar ceolinrenato commented on August 18, 2024

I think a very simple fix like #88 could made the AWS.Signature.sign_v4_query/6 work for this use case

from aws-elixir.

ceolinrenato avatar ceolinrenato commented on August 18, 2024

We could also update test/aws/signature_test.exs sign_v4_query/6 test, since it seems to be target to the same use case. We need to add data to the query string instead of headers

from aws-elixir.

philss avatar philss commented on August 18, 2024

Hi @ceolinrenato 👋
Thank you for opening the issue and the PR. Unfortunately we just removed the signature part from this library. The idea is to keep signature features in https://github.com/aws-beam/aws_signature and share that lib with the generated packages (aws-elixir and aws-erlang).
I think we can support this feature in that lib too.

I'm closing the issue and the PR, but I have opened a new issue there: aws-beam/aws_signature#4
Thanks again!

from aws-elixir.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.