NXDOMAIN when calling CostExplorer.get_cost_and_usage
Closed this issue ยท 5 comments
When I call AWS.CostExplorer.get_cost_and_usage
I get {:error, :nxdomain}
.
According to the AWS docs, the provided endpoint is available at https://ce.us-east-1.amazonaws.com
, while if I can understand it correctly, the current implementation tries to reach it https://ce.amazonaws.com/
which is in fact non-existent.
Working example:
def list_services() do
# Configure ExAws with your AWS credentials
client = AWS.Client.create()
{:ok, _, response} =
AWS.CostExplorer.get_cost_and_usage(client, %{
"TimePeriod" => %{
"Start" => "2023-01-01",
"End" => "2023-01-31"
},
"Granularity" => "MONTHLY",
"Metrics" => ["BlendedCost"],
"GroupBy" => [%{"Type" => "DIMENSION", "Key" => "SERVICE"}],
"Filter" => %{
"Dimensions" => %{
"Key" => "REGION",
# Specify regions here
"Values" => ["us-east-1", "us-west-2"]
}
}
})
end
Hi @Shadowbeetle ๐ It's been a while since I looked into the Client
implementation so bear with me while we figure this out together ๐
I believe you're landing in: request.ex#L201-L207 due to cost_explorer.ex#L34 which appears to be broken which I'm wild-guessing affects all 17 generated modules that define global?: true
in their metadata
.
Any chance you could try out: https://github.com/aws-beam/aws-elixir/tree/fix-global-endpoints?
Which would correctly generate:
iex(6)> AWS.Request.build_host(AWS.Client.create(), AWS.CostExplorer.metadata())
"ce.us-east-1.amazonaws.com"
I believe the problem is a lack of passing in the metadata.credential_scope alternatively client.region if the former is not set. I don't have any Elixir AWS environment setup so can't easily test this myself ๐ข Let me know if you could try this out and I'll PR and roll out a release as soon as you've confirmed ๐
Thanks @onno-vos-dev! Using the branch, it works perfectly, so I can confirm the change on the branch fixes it.
@Shadowbeetle PR created, I'll roll out the release later today (Stockholm time) ๐
@Shadowbeetle Had a bit of a swordfight with my local environment after recently switching to Mac but here we go:
@onno-vos-dev That was qiuck. Thank you! ๐