Title
#general
m

Moruf Ajibike

08/02/2022, 9:33 AM
I get invalid API key error when i curl http://localhost/status. .env file is in the root directory of cloud-pricing-api and is set to contain both the API key I got from infracost auth login and the self generated 32 chars self hosted api key. When I use the API key for thr grahpql endpoint, I get a valid response which indicates the API key is valid. Is there anything I'm missing?
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 9:35 AM
Hi Moruf, can you paste the curl you are using please?
m

Moruf Ajibike

08/02/2022, 9:37 AM
9:38 AM
Returns {"error": "Invalid API key"}
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 9:38 AM
I don’t think there is a
/status
endpoint. Have you tried
/health
. There’s some troubleshooting curls here that might help: https://www.infracost.io/docs/cloud_pricing_api/self_hosted/#troubleshooting
m

Moruf Ajibike

08/02/2022, 9:50 AM
My bad. Thank you. Not sure where I saw the status endpoint.
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 9:51 AM
No worries 😒imple_smile: is it working okay now?
m

Moruf Ajibike

08/02/2022, 9:51 AM
Health and graphl endpoints work. However, when I run infracost breakdown pointing to the selfhosted endpoint, I get invalid API response: 403 forbidden
9:51 AM
We have been notified of the issue
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 9:52 AM
How are you setting the api key for the Infracost CLI?
m

Moruf Ajibike

08/02/2022, 9:54 AM
Environment var and
infracost configure set api_key <api_key>
9:54 AM
Env var name:
INFRACOST_API_KEY
9:55 AM
FYI, infracost is running on one vm and cli on another
9:55 AM
Also /health from vm with cli returns success
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 9:56 AM
does the
/graphql
endpoint return okay from the VM with the CLI?
m

Moruf Ajibike

08/02/2022, 9:57 AM
One sec
10:13 AM
Result for /graphql returns 400. Get query missing. I set the api key in the header with
X-Api-Key: <key>
10:14 AM
Could be that the cli is not picking up the api key?
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 10:15 AM
Yeah it could be either an issue with the API key or an issue with the pricing API endpoint. How have you specified the pricing API endpoint for the CLI?
m

Moruf Ajibike

08/02/2022, 10:20 AM
One sec. Let me get you the code screenshot
10:24 AM
Can you spot any misconfiguration?
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 10:30 AM
nothing obvious. Do you see anything like
Getting pricing details from
in the logs? If so, is that looking at the correct pricing API endpoint?
m

Moruf Ajibike

08/02/2022, 10:34 AM
Yes, the correct api endpoint is showing in the cli logs. It seems to hit a 403 for the resource
azurerm_managed_disk
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 10:39 AM
Okay, I’m not sure. Happy to pair over zoom if you want and we can debug together.
m

Moruf Ajibike

08/02/2022, 10:42 AM
That would be awesome
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 11:06 AM
provider "aws" {
  region                      = "us-east-1" # <<<<< Try changing this to eu-west-1 to compare the costs
  skip_credentials_validation = true
  skip_requesting_account_id  = true
  access_key                  = "mock_access_key"
  secret_key                  = "mock_secret_key"
}

resource "aws_instance" "web_app" {
  ami           = "ami-674cbc1e"
  instance_type = "m5.4xlarge" # <<<<< Try changing this to m5.8xlarge to compare the costs

  root_block_device {
    volume_size = 50
  }

  ebs_block_device {
    device_name = "my_data"
    volume_type = "io1" # <<<<< Try changing this to gp2 to compare costs
    volume_size = 1000
    iops        = 800
  }
}

resource "aws_lambda_function" "hello_world" {
  function_name = "hello_world"
  role          = "arn:aws:lambda:us-east-1:account-id:resource-id"
  handler       = "exports.test"
  runtime       = "nodejs12.x"
  memory_size   = 1024 # <<<<< Try changing this to 512 to compare costs
}

output "aws_instance_type" {
  value = aws_instance.web_app.instance_type
}
11:40 AM
Just checking - do you have any
.env
or
.env.local
files in the directory Infracost is running in?
m

Moruf Ajibike

08/02/2022, 11:40 AM
Yes, i created a .env file with both api key values
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 11:41 AM
can you try without that .env file?
m

Moruf Ajibike

08/02/2022, 11:42 AM
Sure. Let me remove it
11:48 AM
Same error
12:26 PM
I'm getting the same error when I use the examples/main.tf file
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 12:32 PM
@Moruf Ajibike can you paste me the exact error line again?
m

Moruf Ajibike

08/02/2022, 12:35 PM
Sorry I can't copy as it's running on a different machine
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 12:39 PM
Can you try adding an invalid API key request to your list of test curls:
curl -i $INFRACOST_PRICING_API_ENDPOINT/graphql -H "X-Api-Key: WRONG_API_KEY"
I want to see if that returns an “Invalid API key” error or a “403 Forbidden” error
m

Moruf Ajibike

08/02/2022, 12:39 PM
Okay one sec
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 12:40 PM
And try setting
INFRACOST_API_KEY
env variable to WRONG_API_KEY as well to see if it changes the error for the CLI
m

Moruf Ajibike

08/02/2022, 12:40 PM
Okay
12:48 PM
The curls failed with 403 forbidden, invalid api key
12:48 PM
Infracost breakdown failed with invalid api response 403 forbidden
12:49 PM
Same error as when a valid api key is used
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 12:51 PM
Interesting, we would expect
error="Invalid API key"
for the CLI, so this makes me think it’s not the Cloud Pricing API returning the error but something else. That would also make sense by the fact we’re not seeing any logs in the Cloud Pricing API for these requests.
12:51 PM
So now I’m wondering if you have a HTTP proxy set and if that is returning this error?
m

Moruf Ajibike

08/02/2022, 12:54 PM
Not entirely sure if there is a proxy on the agent. Is there a way I can disable proxy for the cli command?
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 12:56 PM
Is there a way I can disable proxy for the cli command?
No, we just pick up whatever is in the environment. Can you echo out $http_proxy $https_proxy $HTTP_PROXY and $HTTPS_PROXY. We might be able to tell from that.
m

Moruf Ajibike

08/02/2022, 12:56 PM
Okay
1:01 PM
Yes HTTP_PROXY & HTTPS_PROXY values are set
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 1:02 PM
ok interesting. Can you try changing your curl commands to use
curl --proxy="$HTTP_PROXY" ...
and we can see if they have the same error
m

Moruf Ajibike

08/02/2022, 1:02 PM
Ok
1:15 PM
I get 403 forbidden
1:16 PM
The cli command also returns 403 forbidden
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 1:17 PM
okay, so it seems it is the HTTP PROXY causing the issue. You could try
export no_proxy=<vm>:<port>
with your VM’s IP and port and see if that works.
m

Moruf Ajibike

08/02/2022, 1:18 PM
Let me try that
1:33 PM
It was the bloody proxy. It' working now. THANK YOU VERY MUCH.
Alistair (Infracost)

Alistair (Infracost)

08/02/2022, 1:41 PM
BOOOM! 🚀 awesome
5:13 PM
@Moruf Ajibike I’ve added a note to the Troubleshooting guide (https://www.infracost.io/docs/cloud_pricing_api/self_hosted/#troubleshooting) about this issue. I know there’s more we could do in the CLI to help with this, but wanted to get something in the docs for other people if they come across. Thanks for your help with this.
m

Moruf Ajibike

08/02/2022, 6:36 PM
That's great. Happy we managed to resolve the issue.