0
1

More than 3 years have passed since last update.

aws lambda で UnauthorizedOperation エラー

Last updated at Posted at 2021-05-17

aws の lambda で EC2 のリストを生成したく、describe_instances(python3.8/boto3)を実行したら以下のエラー。

Response
{
  "errorMessage": "An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation: You are not authorized to perform this operation.",
  "errorType": "ClientError",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 8, in lambda_handler\n    response = ec2client.describe_instances()\n",
    "  File \"/var/runtime/botocore/client.py\", line 357, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n",
    "  File \"/var/runtime/botocore/client.py\", line 676, in _make_api_call\n    raise error_class(parsed_response, operation_name)\n"
  ]
}

DescribeInstances operation をコールするときに、UnauthorizedOperation = 権限無いよ のエラー発生。
とのことなので、IAM のロール設定を見直す。

Lmbda → 関数 → 対象Lambda関数 → 設定タブ → アクセス権限 → 実行ロール →
【ポリシーをアタッチします】 → 【AmazonEC2ReadOnlyAccess】 選択

無事、エラーは出なくなりました。

めでたしめでたし。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1