I get invalid API key error when i curl <http://lo...
# general
b
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?
l
Hi Moruf, can you paste the curl you are using please?
b
Returns {"error": "Invalid API key"}
l
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
b
My bad. Thank you. Not sure where I saw the status endpoint.
l
No worries simple smile is it working okay now?
b
Health and graphl endpoints work. However, when I run infracost breakdown pointing to the selfhosted endpoint, I get invalid API response: 403 forbidden
We have been notified of the issue
l
How are you setting the api key for the Infracost CLI?
b
Environment var and
infracost configure set api_key <api_key>
Env var name:
INFRACOST_API_KEY
FYI, infracost is running on one vm and cli on another
Also /health from vm with cli returns success
l
does the
/graphql
endpoint return okay from the VM with the CLI?
b
One sec
Result for /graphql returns 400. Get query missing. I set the api key in the header with
X-Api-Key: <key>
Could be that the cli is not picking up the api key?
l
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?
b
One sec. Let me get you the code screenshot
Can you spot any misconfiguration?
l
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?
b
Yes, the correct api endpoint is showing in the cli logs. It seems to hit a 403 for the resource
azurerm_managed_disk
l
Okay, I’m not sure. Happy to pair over zoom if you want and we can debug together.
b
That would be awesome
l
Copy code
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
}
Just checking - do you have any
.env
or
.env.local
files in the directory Infracost is running in?
b
Yes, i created a .env file with both api key values
l
can you try without that .env file?
b
Sure. Let me remove it
Same error
I'm getting the same error when I use the examples/main.tf file
l
@bumpy-match-12594 can you paste me the exact error line again?
b
Sorry I can't copy as it's running on a different machine
l
Can you try adding an invalid API key request to your list of test curls:
Copy code
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
b
Okay one sec
l
And try setting
INFRACOST_API_KEY
env variable to WRONG_API_KEY as well to see if it changes the error for the CLI
b
Okay
The curls failed with 403 forbidden, invalid api key
Infracost breakdown failed with invalid api response 403 forbidden
Same error as when a valid api key is used
l
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.
So now I’m wondering if you have a HTTP proxy set and if that is returning this error?
b
Not entirely sure if there is a proxy on the agent. Is there a way I can disable proxy for the cli command?
l
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.
b
Okay
Yes HTTP_PROXY & HTTPS_PROXY values are set
l
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
b
Ok
I get 403 forbidden
The cli command also returns 403 forbidden
l
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.
b
Let me try that
It was the bloody proxy. It' working now. THANK YOU VERY MUCH.
l
BOOOM! 🚀 awesome
@bumpy-match-12594 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.
b
That's great. Happy we managed to resolve the issue.