MeWrite Docs

AWS: AccessDenied

AWSでIAMポリシーによりアクセスが拒否された場合のエラー

概要

AWSリソースへのアクセス時に、IAMポリシーによって必要な権限が付与されていない場合に発生するエラーです。

エラーメッセージ

An error occurred (AccessDenied) when calling the GetObject operation: Access Denied

または

User: arn:aws:iam::123456789012:user/myuser is not authorized to perform: s3:GetObject on resource: arn:aws:s3:::mybucket/mykey

原因

  1. IAMポリシー不足: 必要なアクションがポリシーで許可されていない
  2. リソースベースポリシー: S3バケットポリシーなどで拒否されている
  3. SCPによる制限: Organizations のサービスコントロールポリシー
  4. 条件の不一致: IPアドレスやMFA条件を満たしていない

解決策

1. IAMポリシーの確認

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

2. IAM Policy Simulator で検証

1
2
3
4
5
# AWS CLI でポリシーをシミュレート
aws iam simulate-principal-policy \
  --policy-source-arn arn:aws:iam::123456789012:user/myuser \
  --action-names s3:GetObject \
  --resource-arns arn:aws:s3:::mybucket/mykey

3. S3バケットポリシーの確認

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::123456789012:user/myuser"
      },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::mybucket/*"
    }
  ]
}

4. CloudTrailでログ確認

1
2
3
4
# 直近のアクセス拒否イベントを検索
aws cloudtrail lookup-events \
  --lookup-attributes AttributeKey=EventName,AttributeValue=GetObject \
  --start-time $(date -d '1 hour ago' --iso-8601=seconds)

5. STS で現在のIDを確認

1
2
3
4
5
6
7
8
9
# 現在使用中の認証情報を確認
aws sts get-caller-identity

# 出力例
{
  "UserId": "AIDAXXXXXXXXXXXXXXXXX",
  "Account": "123456789012",
  "Arn": "arn:aws:iam::123456789012:user/myuser"
}

6. AssumeRole の確認

1
2
3
4
5
6
7
# ロールを引き受けているか確認
aws sts get-caller-identity

# 必要に応じてロールを引き受け
aws sts assume-role \
  --role-arn arn:aws:iam::123456789012:role/MyRole \
  --role-session-name MySession

7. MFA条件の確認

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": "*",
      "Condition": {
        "Bool": {
          "aws:MultiFactorAuthPresent": "true"
        }
      }
    }
  ]
}

8. VPCエンドポイントポリシー

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:*",
      "Resource": [
        "arn:aws:s3:::mybucket",
        "arn:aws:s3:::mybucket/*"
      ]
    }
  ]
}

9. Access Analyzer で分析

1
2
3
4
# IAM Access Analyzer を使用してポリシーを検証
aws accessanalyzer validate-policy \
  --policy-type IDENTITY_POLICY \
  --policy-document file://policy.json

よくある間違い

  • バケット名とバケット内オブジェクトのARNを混同(arn:aws:s3:::bucket vs arn:aws:s3:::bucket/*
  • ワイルドカードの使い方(*/* の違い)
  • クロスアカウントアクセスでプリンシパルの指定ミス
  • 暗黙の拒否と明示的な拒否の優先順位

AWS の他のエラー

最終更新: 2025-12-09