Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds 'member' to map/list members #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

namjae
Copy link

@namjae namjae commented Nov 1, 2024

without member keyword between the parameters and the numbers, I got following error

{:error,
 {:unexpected_response,
  %{
    body: "<ErrorResponse xmlns=\"http://monitoring.amazonaws.com/doc/2010-08-01/\">\n  <Error>\n    <Type>Sender</Type>\n    <Code>MalformedInput</Code>\n    <Message>Top level element may not be treated as a list</Message>\n  </Error>\n  <RequestId>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</RequestId>\n</ErrorResponse>\n",
    headers: [
      {"x-amzn-RequestId", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"},
      {"Content-Type", "text/xml"},
      {"Content-Length", "298"},
      {"Date", "Fri, 01 Nov 2024 07:54:27 GMT"},
      {"Connection", "close"}
    ],
    status_code: 400
  }}}

@onno-vos-dev
Copy link
Member

onno-vos-dev commented Nov 1, 2024

Can you show me your request? I believe this is an issue with your request rather than the util code and this may break for basically every other request :-)

I'd need to think about this a little bit since the aws-elixir util is slightly different from the Erlang one which I'm more used to using 👍

I'm wondering, can't this be solved by setting the key to: Baz.member which I wouldn't be surprised of aws-elixir are doing today?

@onno-vos-dev
Copy link
Member

Suggestion to be safe in case any users currently supply the key as Bar.member to work around this issue? WDYT?

defp encode_query_value({key, value}) when is_list(value) do
  value
  |> Enum.with_index(1)
  |> Enum.map(fn {inner_value, idx} ->
    encode_query_value({maybe_add_member(key, to_string(idx), inner_value})
  end)
end
  
defp maybe_add_member(key, idx) do
  if String.contains?(key, ".member")
    [key, ?., to_string(idx)]
  else
    [key, ?., "member", ?., to_string(idx)]
  end
end

@namjae
Copy link
Author

namjae commented Nov 1, 2024

@onno-vos-dev here's my test function

  def test do
    end_time = Timex.now()
    start_time = end_time |> Timex.subtract(Timex.Duration.from_minutes(5))

    client = %AWS.Client{
      access_key_id: "XXXXXXXXXXXXXXXXXXXX",
      secret_access_key: "xxXxXxXxXXXxxxXXxXXxxxxxXXxxxxxxXxXxXxXx",
      region: "ap-northeast-2"
    }

    input = %{"Namespace" => "AWS/RDS",
              "MetricName" => "FreeStorageSpace",
              "StartTime" => start_time |> Timex.format!("%FT%T", :strftime),
              "EndTime" => end_time |> Timex.format!("%FT%T", :strftime),
              "Period" => 300,
              "Statistics" => ["Average"],
              "Dimensions" => [%{"Name" => "DBInstanceIdentifier", "Value" => "xxx-xxxxxx-xxx"}]
              }

    AWS.CloudWatch.get_metric_statistics(client, input)
  end

@onno-vos-dev
Copy link
Member

@namjae Can you update the PR to accommodate my comment?

Then I'd be open to this PR 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants