Page 1 of 3

boto3 caught_exception botocore.exceptions.EndpointConnectio

Posted: Mon May 20, 2019 5:47 am
by sgargano
Dear all,

we have just installed boto3 as requested by the AWS Wizard.

The Wizard itself works perfectly, we were able to pass the credentials and any information requested.

But we got some error even launching manually the command:

Code: Select all

sudo ./check_ec2.py -P 5 --metricname CPUCreditBalance --instanceid 'i-xxxxxxxx' --accesskeyid 'ACCESSKEY' --secretaccesskey 'SECRETYKEY' --region 'eu-central-1b' --warning '100:' --critical '25:'

Code: Select all

Traceback (most recent call last):
  File "./check_ec2.py", line 561, in <module>
    main()
  File "./check_ec2.py", line 460, in main
    check_ec2(options.metricname, options.instanceid, options.period, statistics, options.accesskeyid, options.secretaccesskey, options.region)
  File "./check_ec2.py", line 139, in check_ec2
    Statistics=statistics
  File "/usr/lib/python2.7/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/lib/python2.7/site-packages/botocore/client.py", line 648, in _make_api_call
    operation_model, request_dict, request_context)
  File "/usr/lib/python2.7/site-packages/botocore/client.py", line 667, in _make_request
    return self._endpoint.make_request(operation_model, request_dict)
  File "/usr/lib/python2.7/site-packages/botocore/endpoint.py", line 102, in make_request
    return self._send_request(request_dict, operation_model)
  File "/usr/lib/python2.7/site-packages/botocore/endpoint.py", line 137, in _send_request
    success_response, exception):
  File "/usr/lib/python2.7/site-packages/botocore/endpoint.py", line 231, in _needs_retry
    caught_exception=caught_exception, request_dict=request_dict)
  File "/usr/lib/python2.7/site-packages/botocore/hooks.py", line 356, in emit
    return self._emitter.emit(aliased_event_name, **kwargs)
  File "/usr/lib/python2.7/site-packages/botocore/hooks.py", line 228, in emit
    return self._emit(event_name, kwargs)
  File "/usr/lib/python2.7/site-packages/botocore/hooks.py", line 211, in _emit
    response = handler(**kwargs)
  File "/usr/lib/python2.7/site-packages/botocore/retryhandler.py", line 183, in __call__
    if self._checker(attempts, response, caught_exception):
  File "/usr/lib/python2.7/site-packages/botocore/retryhandler.py", line 251, in __call__
    caught_exception)
  File "/usr/lib/python2.7/site-packages/botocore/retryhandler.py", line 277, in _should_retry
    return self._checker(attempt_number, response, caught_exception)
  File "/usr/lib/python2.7/site-packages/botocore/retryhandler.py", line 317, in __call__
    caught_exception)
  File "/usr/lib/python2.7/site-packages/botocore/retryhandler.py", line 223, in __call__
    attempt_number, caught_exception)
  File "/usr/lib/python2.7/site-packages/botocore/retryhandler.py", line 359, in _check_caught_exception
    raise caught_exception
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://monitoring.eu-central-1b.amazonaws.com/"
I tried to modify the Region to "eu-central-1" without "b" and I got this error:

Code: Select all

sudo ./check_ec2.py -P 5 --metricname CPUCreditBalance --instanceid 'i-xxxxxxxx' --accesskeyid 'ACCESSKEY' --secretaccesskey 'SECRETYKEY' --region 'eu-central-1' --warning '100:' --critical '25:'

Code: Select all

The check has received a response with no data. This is generally caused by an incorrect region name, invalid metric name, or invalid instance ID.
Please verify the following:
Region: eu-central-1
Metric: CPUCreditBalance
Instance ID: i-xxxxxxxxxxxxxxx
Currently all the information looks correct!
Do you have any suggestion or workaround to avoid those errors?

Re: boto3 caught_exception botocore.exceptions.EndpointConne

Posted: Mon May 20, 2019 12:19 pm
by scottwilkerson
Are you 100% sure i-xxxxxxxxxxxxxxx is active AND in that region?

Re: boto3 caught_exception botocore.exceptions.EndpointConne

Posted: Wed May 22, 2019 7:59 am
by sgargano
scottwilkerson wrote:Are you 100% sure i-xxxxxxxxxxxxxxx is active AND in that region?
yes they are,
should we enable some security rule from AWS or some API function for the metrics?

Re: boto3 caught_exception botocore.exceptions.EndpointConne

Posted: Wed May 22, 2019 8:23 am
by sgargano
./check_ec2.py -P 5 --metricname CPUCreditBalance --instanceid 'i-' --accesskeyid '' --secretaccesskey '' --region 'eu-central-1' --warning '100:' --critical '25:'
The check has received a response with no data. This is generally caused by an incorrect region name, invalid metric name, or invalid instance ID.
Please verify the following:
Region: eu-central-1
Metric: CPUCreditBalance
Instance ID: i-........

created a new user in aws for nagios to double check
but same issue..

Re: boto3 caught_exception botocore.exceptions.EndpointConne

Posted: Wed May 22, 2019 9:03 am
by scottwilkerson
Is this a Burstable Performance Instances? I believe these metrics are only available if they are

https://docs.aws.amazon.com/AWSEC2/late ... cw-metrics

Re: boto3 caught_exception botocore.exceptions.EndpointConne

Posted: Fri May 24, 2019 7:34 am
by sgargano
yes it is a t2 and we can see the metrics on CloudWatch.

Re: boto3 caught_exception botocore.exceptions.EndpointConne

Posted: Fri May 24, 2019 7:46 am
by scottwilkerson
The users do need permissions to cloudwatch in AWS, such as CloudWatchFullAccess policy

Re: boto3 caught_exception botocore.exceptions.EndpointConne

Posted: Tue May 28, 2019 9:05 am
by sgargano
yes we checked the user permissions and we are able to see the results by using the AWS cli:

Code: Select all

C:\Users\ss>aws cloudwatch get-metric-statistics --metric-name CPUUtilization --start-time 2019-05-28T10:18:00Z --end-time 2019-05-28T11:18:00Z --period 3600 --namespace AWS/EC2 --statistics Maximum --dimensions Name=InstanceId,Value=i-xxxxxxxxx

{

    "Datapoints": [

        {

            "Timestamp": "2019-05-28T10:18:00Z",

            "Maximum": 2.06896551724107,

            "Unit": "Percent"

        }

    ],

    "Label": "CPUUtilization"

}

Re: boto3 caught_exception botocore.exceptions.EndpointConne

Posted: Tue May 28, 2019 9:23 am
by scottwilkerson
The metric you were previously trying to get and failed was CPUCreditBalance not CPUUtilization

Re: boto3 caught_exception botocore.exceptions.EndpointConne

Posted: Wed May 29, 2019 2:45 am
by sgargano
[root@chlugmw1 ~]# aws cloudwatch get-metric-statistics --metric-name CPUCreditBalance --start-time 2019-05-28T10:18:00Z --end-time 2019-05-28T11:18:00Z --period 3600 --namespace AWS/EC2 --statistics Maximum --dimensions Name=InstanceId,Value=i-xxxxxxx
{
"Datapoints": [
{
"Timestamp": "2019-05-28T10:18:00Z",
"Maximum": 288.0,
"Unit": "Count"
}
],
"Label": "CPUCreditBalance"
}