MeWrite Docs

AccessDeniedException: User is not authorized

AWS APIでIAM権限が不足している場合に発生するエラー

概要

AccessDeniedException: User: arn:aws:iam::xxx is not authorized to perform は、AWSのAPIを呼び出した際に、IAMユーザーまたはロールに必要な権限がない場合に発生するエラーです。

エラーメッセージ

An error occurred (AccessDeniedException) when calling the DescribeInstances operation: User: arn:aws:iam::123456789012:user/developer is not authorized to perform: ec2:DescribeInstances on resource: *
AccessDeniedException: User: arn:aws:sts::123456789012:assumed-role/MyRole/session is not authorized to perform: dynamodb:GetItem on resource: arn:aws:dynamodb:ap-northeast-1:123456789012:table/MyTable
An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied

原因

1. IAMポリシーに権限がない

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject"],
      "Resource": "*"
    }
  ]
}
// s3:ListBucketがないためリスト取得でエラー

2. リソースベースポリシーの制限

S3バケットポリシーなどで明示的に拒否されている場合です。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  "Effect": "Deny",
  "Principal": "*",
  "Action": "s3:*",
  "Resource": "arn:aws:s3:::my-bucket/*",
  "Condition": {
    "StringNotEquals": {
      "aws:PrincipalAccount": "123456789012"
    }
  }
}

3. SCPによる制限

Organizations SCPで操作が制限されている場合です。

4. 権限境界(Permissions Boundary)

IAMユーザー/ロールに設定された権限境界で制限されている場合です。

5. 間違った認証情報

別のアカウントの認証情報を使用している場合です。

1
2
# 現在の認証情報を確認
aws sts get-caller-identity

解決策

1. 現在の認証情報を確認

1
aws sts get-caller-identity

出力例:

1
2
3
4
5
{
  "UserId": "AIDAXXXXXXXXXX",
  "Account": "123456789012",
  "Arn": "arn:aws:iam::123456789012:user/developer"
}

2. 必要な権限を追加

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ec2:DescribeInstances",
        "ec2:DescribeSecurityGroups"
      ],
      "Resource": "*"
    }
  ]
}

3. IAM Policy Simulatorで検証

AWS ConsoleのIAM Policy Simulatorを使って、どの権限が不足しているか確認できます。

4. CloudTrailでエラーを確認

1
2
3
aws cloudtrail lookup-events \
  --lookup-attributes AttributeKey=EventName,AttributeValue=DescribeInstances \
  --start-time 2024-01-01T00:00:00Z

5. 最小権限の原則に従った設定

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowSpecificS3Access",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject"
      ],
      "Resource": "arn:aws:s3:::my-bucket/prefix/*"
    }
  ]
}

6. AssumeRoleの確認

クロスアカウントやロール切り替え時は信頼ポリシーも確認します。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::123456789012:user/developer"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

よくあるケース別対処

Lambda関数からのアクセス

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "dynamodb:GetItem",
        "dynamodb:PutItem"
      ],
      "Resource": "arn:aws:dynamodb:*:*:table/MyTable"
    }
  ]
}

ECS タスクからのアクセス

タスクロール(taskRoleArn)に権限を付与します。

1
2
3
{
  "taskRoleArn": "arn:aws:iam::123456789012:role/ecsTaskRole"
}

デバッグ手順

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 1. 認証情報の確認
aws sts get-caller-identity

# 2. 使用中のプロファイル確認
echo $AWS_PROFILE

# 3. 特定アクションの権限テスト
aws iam simulate-principal-policy \
  --policy-source-arn arn:aws:iam::123456789012:user/developer \
  --action-names ec2:DescribeInstances

# 4. ポリシー一覧
aws iam list-attached-user-policies --user-name developer

関連エラー

関連エラー

AWS の他のエラー

最終更新: 2025-12-17