{
  "id": "aws/lambda-snapstart-classpath-error",
  "signature": "SnapStart classpath error: Failed to load class from snapshot due to classpath mismatch",
  "signature_zh": "SnapStart类路径错误：由于类路径不匹配，无法从快照加载类",
  "regex": "SnapStart classpath error|Failed to load class from snapshot due to classpath mismatch",
  "domain": "aws",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Lambda SnapStart snapshot was taken with a different classpath than the runtime environment, often caused by mutable classpath dependencies or environment variable changes after snapshot creation.",
  "root_cause_type": "generic",
  "root_cause_zh": "Lambda SnapStart快照是在与运行时环境不同的类路径下拍摄的，通常是由于在快照创建后修改了类路径依赖项或环境变量。",
  "versions": [
    {
      "version": "Lambda SnapStart (Java 11)",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "AWS SDK for Java 2.21.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Rebuild and redeploy the Lambda function without changing anything else",
      "why_fails": "The root cause is classpath mismatch; simply rebuilding without fixing the mutable dependency issue won't help.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Disable SnapStart and re-enable it",
      "why_fails": "Disabling and re-enabling SnapStart without addressing the classpath mismatch will reproduce the same error.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Increase Lambda memory or timeout",
      "why_fails": "Classpath errors are not related to memory or timeout; these settings don't affect class loading.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure all dependencies are immutable and not downloaded at runtime. Use a layer or bundle all JARs in the deployment package:\n# Example: build a fat JAR with Maven Shade Plugin\nmvn clean package shade:shade\naws lambda update-function-code --function-name my-function --zip-file fileb://target/my-function.jar",
      "success_rate": 0.8,
      "how": "Ensure all dependencies are immutable and not downloaded at runtime. Use a layer or bundle all JARs in the deployment package:\n# Example: build a fat JAR with Maven Shade Plugin\nmvn clean package shade:shade\naws lambda update-function-code --function-name my-function --zip-file fileb://target/my-function.jar",
      "condition": "",
      "sources": []
    },
    {
      "action": "Set environment variables in the function configuration before taking the snapshot, and never change them after:\naws lambda update-function-configuration --function-name my-function --environment Variables={KEY=VALUE} --snap-start ApplyOn=PublishedVersions",
      "success_rate": 0.75,
      "how": "Set environment variables in the function configuration before taking the snapshot, and never change them after:\naws lambda update-function-configuration --function-name my-function --environment Variables={KEY=VALUE} --snap-start ApplyOn=PublishedVersions",
      "condition": "",
      "sources": []
    },
    {
      "action": "Publish a new version after fixing dependencies to take a fresh snapshot:\naws lambda publish-version --function-name my-function",
      "success_rate": 0.85,
      "how": "Publish a new version after fixing dependencies to take a fresh snapshot:\naws lambda publish-version --function-name my-function",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "确保所有依赖项都是不可变的，并且不在运行时下载。使用层或将所有JAR打包到部署包中：\n# 示例：使用Maven Shade Plugin构建胖JAR\nmvn clean package shade:shade\naws lambda update-function-code --function-name my-function --zip-file fileb://target/my-function.jar",
    "在拍摄快照之前，在函数配置中设置环境变量，之后永远不要更改：\naws lambda update-function-configuration --function-name my-function --environment Variables={KEY=VALUE} --snap-start ApplyOn=PublishedVersions",
    "修复依赖项后发布新版本以拍摄新快照：\naws lambda publish-version --function-name my-function"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.aws.amazon.com/lambda/latest/dg/snapstart-troubleshooting.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.78,
  "resolvable": "true",
  "first_seen": "2024-01-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}