IronPDF Lambda部署中的缺少相依性
IronPDF在部署到AWS Lambda時無法初始化,產生以下類似錯誤:
IronPDF failed to start: required native binaries not found at the expected path.
Unable to load shared library or one of its dependencies.
Error: Required IronPDF native dependencies were not found in the deployment package.
Lambda部署中缺少原生相依性是由以下一個或多個原因造成的:
- 缺少權限:Lambda執行角色或檔案系統路徑缺少IronPDF所需的讀/寫/執行權限。
- 缺少原生二進位文件:部屬包中未包含原生IronPDF程式庫。
- Dockerfile不正確:Dockerfile未安裝Lambda基礎映像所需的正確OS級相依性。
解決方案
切換到IronPdf.Slim NuGet套件。 與完整的IronPDF套件不同,IronPdf.Slim會在運行時自動下載檢測到的基礎映像所需的正確原生二進位文件,消除了手動捆綁平台專用二進位文件的需要:
// NuGet: IronPdf.Slim
// IronPdf.Slim selects and downloads the appropriate native runtime
// for the Lambda execution environment automatically.
IronPdf.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPDF_LICENSE_KEY");
var renderer = new ChromePdfRenderer();
var pdf = await renderer.RenderHtmlAsPdfAsync("<h1>Hello from Lambda</h1>");
pdf.SaveAs("/tmp/output.pdf");
// NuGet: IronPdf.Slim
// IronPdf.Slim selects and downloads the appropriate native runtime
// for the Lambda execution environment automatically.
IronPdf.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPDF_LICENSE_KEY");
var renderer = new ChromePdfRenderer();
var pdf = await renderer.RenderHtmlAsPdfAsync("<h1>Hello from Lambda</h1>");
pdf.SaveAs("/tmp/output.pdf");
' NuGet: IronPdf.Slim
' IronPdf.Slim selects and downloads the appropriate native runtime
' for the Lambda execution environment automatically.
IronPdf.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPDF_LICENSE_KEY")
Dim renderer As New ChromePdfRenderer()
Dim pdf = Await renderer.RenderHtmlAsPdfAsync("<h1>Hello from Lambda</h1>")
pdf.SaveAs("/tmp/output.pdf")
直接在Lambda中測試:不要依賴本地測試來驗證原生相依性解決方案。 專案在本地運行時會下載與Windows相容或與主機OS相容的二進位文件,而不是與Lambda相容的二進位文件,導致誤判為通過。
從AWS檢索日誌檔案以獲取診斷細節,當在切換到IronPdf.Slim後問題仍然存在時。 在第一次呼叫IronPDF之前啟用日誌記錄:
IronPdf.Logging.Logger.EnableDebugging = true;
IronPdf.Logging.Logger.LogFilePath = "/tmp/ironpdf.log";
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
IronPdf.Logging.Logger.EnableDebugging = true;
IronPdf.Logging.Logger.LogFilePath = "/tmp/ironpdf.log";
IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;
Imports IronPdf.Logging
Logger.EnableDebugging = True
Logger.LogFilePath = "/tmp/ironpdf.log"
Logger.LoggingMode = Logger.LoggingModes.All
在您的支援請求中附加/tmp/ironpdf.log和Lambda CloudWatch日誌輸出。另請參閱:將IronPDF部署到AWS Lambda與Docker和如何獲取IronPDF在AWS中的日誌檔案。

