errorMessage An error occurred UnauthorizedOperation when calling the DescribeInstanceStatus operation You are not authorized

0 votes

I am trying to run AWS Lambda function to fetch status of my instances. But I got the below error.

Response:
{
  "errorMessage": "An error occurred (UnauthorizedOperation) when calling the DescribeInstanceStatus operation: You are not authorized to perform this operation.",
  "errorType": "ClientError",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 7, in lambda_handler\n    status = client.describe_instance_status(IncludeAllInstances = True)\n",
    "  File \"/var/runtime/botocore/client.py\", line 272, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n",
    "  File \"/var/runtime/botocore/client.py\", line 576, in _make_api_call\n    raise error_class(parsed_response, operation_name)\n"
  ]
}
Request ID:
"6c94f062-dab7-421e-9d58-e0967741abe1"
Function Logs:
START RequestId: 6c94f062-dab7-421e-9d58-e0967741abe1 Version: $LATEST
[ERROR] ClientError: An error occurred (UnauthorizedOperation) when calling the DescribeInstanceStatus operation: You are not authorized to perform this operation.
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 7, in lambda_handler
    status = client.describe_instance_status(IncludeAllInstances = True)
  File "/var/runtime/botocore/client.py", line 272, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/var/runtime/botocore/client.py", line 576, in _make_api_call
    raise error_class(parsed_response, operation_name)END RequestId: 6c94f062-dab7-421e-9d58-e0967741abe1
REPORT RequestId: 6c94f062-dab7-421e-9d58-e0967741abe1 Duration: 1683.86 ms Billed Duration: 1700 ms Memory Size: 128 MB Max Memory Used: 79 MB Init Duration: 243.28 ms

How can I solve this error?

Thank You

Apr 2, 2020 in AWS by akhtar
• 38,260 points
6,658 views

1 answer to this question.

0 votes

Hi@akhtar,

You are not able to access your EC2 instances using Lambda function. To get the authorization you have to add one policy in your AWS Lambda function. Edit your Lambda function role and add AmazonEC2ReadOnlyAccess policy.

Now, try to run again. It will work.

Thank You

answered Apr 2, 2020 by MD
• 95,460 points

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
+2 votes
3 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP