Amazon Linux 2 üzerinde AWS Lambda ile IronPDF
AWS Lambda / Amazon Linux 2 (Admin/root olarak IronPdf.Linux kullanarak yükleyin)
Bu bilgi ayrıca web sitemizde de gösterilmektedir - AWS Lambda IronPDF Kılavuzu
AWS Talimatları
-
AWS .NET 5 Lambda Desteği ve Container Image'ları makalesine bakın
-
Aşağıdaki Dockerfile'ı oluşturun ve kullanın:
# Use the .NET 8 AWS Lambda runtime as the base image FROM public.ecr.aws/lambda/dotnet:8 WORKDIR /var/task # Install the necessary dependencies for IronPDF RUN yum install -y pango.x86_64 \ libXcomposite.x86_64 \ libXcursor.x86_64 \ libXdamage.x86_64 \ libXext.x86_64 \ libXi.x86_64 \ libXtst.x86_64 \ cups-libs.x86_64 \ libXScrnSaver.x86_64 \ libXrandr.x86_64 \ GConf2.x86_64 \ alsa-lib.x86_64 \ atk.x86_64 \ gtk3.x86_64 \ ipa-gothic-fonts \ xorg-x11-fonts-100dpi \ xorg-x11-fonts-75dpi \ xorg-x11-utils \ xorg-x11-fonts-cyrillic \ xorg-x11-fonts-Type1 \ xorg-x11-fonts-misc \ glibc-devel.x86_64 \ at-spi2-atk.x86_64 \ mesa-libgbm.x86_64 # This COPY command copies the .NET Lambda project's build artifacts from the host machine into the image. COPY "bin/Release/lambda-publish" .Dockerfile -
Çözümünüze IronPdf.Linux paketini ekleyin.
-
_FunctionHandlerkodunu değiştirin - bu örnek bir web sayfasından (IronPDF) PDF oluşturacak ve/tmpkonumuna kaydedecek. Bu PDF'i görüntülemek için, S3 gibi başka bir servise yüklenmesi gerekir. (Resmi AWS örneği burada - AWS S3 Temel Bilgiler)// Define the function handler for AWS Lambda public Casing FunctionHandler(string input, ILambdaContext context) { try { // Start logging the function process with input details context.Logger.LogLine($"START FunctionHandler RequestId: {context.AwsRequestId} Input: {input}"); var awsTmpPath = @"/tmp/"; // AWS temporary storage path // Optional: Enable debugging for IronPdf // IronPdf.Logging.Logger.EnableDebugging = true; // IronPdf.Logging.Logger.LogFilePath = awsTmpPath; // IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All; // Set your license key for IronPDF IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY"; // Configuration for IronPDF rendering IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled; IronPdf.Installation.DefaultRenderingEngine = IronPdf.Rendering.PdfRenderingEngine.Chrome; Environment.SetEnvironmentVariable("TEMP", awsTmpPath, EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("TMP", awsTmpPath, EnvironmentVariableTarget.Process); IronPdf.Installation.TempFolderPath = awsTmpPath; IronPdf.Installation.CustomDeploymentDirectory = awsTmpPath; IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true; context.Logger.LogLine($"Creating IronPdf.ChromePdfRenderer"); // Create instance of ChromePdfRenderer and render PDF from URL var renderer = new IronPdf.ChromePdfRenderer(); context.Logger.LogLine($"Rendering PDF"); using var pdfDoc = renderer.RenderUrlAsPdf("https://ironpdf.com/"); var guid = Guid.NewGuid(); var fileName = $"/tmp/{input}_{guid}.pdf"; // Name for the PDF file // Save the rendered PDF document context.Logger.LogLine($"Saving PDF name : {fileName}"); pdfDoc.SaveAs(fileName); // Here you can upload the saved PDF file to anywhere such as AWS S3. context.Logger.LogLine($"COMPLETE!"); } catch (Exception e) { // Log errors if any occur context.Logger.LogLine($"[ERROR] FunctionHandler : {e.Message}"); } // Return a new instance of Casing with lower and upper case input strings return new Casing(input?.ToLower(), input?.ToUpper()); } // Casing record to hold lower and upper case strings public record Casing(string Lower, string Upper);' Define the function handler for AWS Lambda Public Function FunctionHandler(ByVal input As String, ByVal context As ILambdaContext) As Casing Try ' Start logging the function process with input details context.Logger.LogLine($"START FunctionHandler RequestId: {context.AwsRequestId} Input: {input}") Dim awsTmpPath = "/tmp/" ' AWS temporary storage path ' Optional: Enable debugging for IronPdf ' IronPdf.Logging.Logger.EnableDebugging = true; ' IronPdf.Logging.Logger.LogFilePath = awsTmpPath; ' IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All; ' Set your license key for IronPDF IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY" ' Configuration for IronPDF rendering IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled IronPdf.Installation.DefaultRenderingEngine = IronPdf.Rendering.PdfRenderingEngine.Chrome Environment.SetEnvironmentVariable("TEMP", awsTmpPath, EnvironmentVariableTarget.Process) Environment.SetEnvironmentVariable("TMP", awsTmpPath, EnvironmentVariableTarget.Process) IronPdf.Installation.TempFolderPath = awsTmpPath IronPdf.Installation.CustomDeploymentDirectory = awsTmpPath IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = True context.Logger.LogLine($"Creating IronPdf.ChromePdfRenderer") ' Create instance of ChromePdfRenderer and render PDF from URL Dim renderer = New IronPdf.ChromePdfRenderer() context.Logger.LogLine($"Rendering PDF") Dim pdfDoc = renderer.RenderUrlAsPdf("https://ironpdf.com/") Dim guid As System.Guid = System.Guid.NewGuid() Dim fileName = $"/tmp/{input}_{guid}.pdf" ' Name for the PDF file ' Save the rendered PDF document context.Logger.LogLine($"Saving PDF name : {fileName}") pdfDoc.SaveAs(fileName) ' Here you can upload the saved PDF file to anywhere such as AWS S3. context.Logger.LogLine($"COMPLETE!") Catch e As Exception ' Log errors if any occur context.Logger.LogLine($"[ERROR] FunctionHandler : {e.Message}") End Try ' Return a new instance of Casing with lower and upper case input strings Return New Casing(input?.ToLower(), input?.ToUpper()) End Function ' Casing record to hold lower and upper case strings 'INSTANT VB TODO TASK: C# 'records' are not converted by Instant VB: 'public record Casing(string Lower, string Upper)' Define the function handler for AWS Lambda Public Function FunctionHandler(ByVal input As String, ByVal context As ILambdaContext) As Casing Try ' Start logging the function process with input details context.Logger.LogLine($"START FunctionHandler RequestId: {context.AwsRequestId} Input: {input}") Dim awsTmpPath = "/tmp/" ' AWS temporary storage path ' Optional: Enable debugging for IronPdf ' IronPdf.Logging.Logger.EnableDebugging = true; ' IronPdf.Logging.Logger.LogFilePath = awsTmpPath; ' IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All; ' Set your license key for IronPDF IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY" ' Configuration for IronPDF rendering IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled IronPdf.Installation.DefaultRenderingEngine = IronPdf.Rendering.PdfRenderingEngine.Chrome Environment.SetEnvironmentVariable("TEMP", awsTmpPath, EnvironmentVariableTarget.Process) Environment.SetEnvironmentVariable("TMP", awsTmpPath, EnvironmentVariableTarget.Process) IronPdf.Installation.TempFolderPath = awsTmpPath IronPdf.Installation.CustomDeploymentDirectory = awsTmpPath IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = True context.Logger.LogLine($"Creating IronPdf.ChromePdfRenderer") ' Create instance of ChromePdfRenderer and render PDF from URL Dim renderer = New IronPdf.ChromePdfRenderer() context.Logger.LogLine($"Rendering PDF") Dim pdfDoc = renderer.RenderUrlAsPdf("https://ironpdf.com/") Dim guid As System.Guid = System.Guid.NewGuid() Dim fileName = $"/tmp/{input}_{guid}.pdf" ' Name for the PDF file ' Save the rendered PDF document context.Logger.LogLine($"Saving PDF name : {fileName}") pdfDoc.SaveAs(fileName) ' Here you can upload the saved PDF file to anywhere such as AWS S3. context.Logger.LogLine($"COMPLETE!") Catch e As Exception ' Log errors if any occur context.Logger.LogLine($"[ERROR] FunctionHandler : {e.Message}") End Try ' Return a new instance of Casing with lower and upper case input strings Return New Casing(input?.ToLower(), input?.ToUpper()) End Function ' Casing record to hold lower and upper case strings 'INSTANT VB TODO TASK: C# 'records' are not converted by Instant VB: 'public record Casing(string Lower, string Upper) -
Bellek ve zaman aşımını artırın - IronPDF, Lambda'nın varsayılan değerinden daha fazla zaman ve bellek gerektirir. Bu,
aws-lambda-tools-defaults.jsoniçinde yapılandırılabilir. Bu değerleri, fonksiyonunuzun ihtiyaçlarına göre ayarlayın.
Bu örnekte, 512 (MB) ve 330 (saniye) olarak ayarladık:
"function-memory-size": 512,
"function-timeout": 330,
Ayarlar ayrıca Lambda konsolunu kullanarak da güncellenebilir - AWS Lambda Bellek Yapılandırması.
- Bir Lambda fonksiyonu yayımlamak ve denemek için AWS .NET 5 Lambda Desteği ve Container Image'ları belgesinin son bölümündeki adımları izleyin.
- Lambda fonksiyonu, AWS Lambda Konsolu üzerinden veya Visual Studio'da Visual Studio için AWS Araç Kiti kullanılarak da çağrılabilir.
"GPU işlemcisi kullanılamaz" mesajı alırsanız, kurulumun yönetici ayrıcalıkları ile çalıştırılmadığı anlaşılabilir. Lütfen yazılımı yönetici/kök ayrıcalıkları ile tekrar çalıştırmayı deneyin. Alternatif olarak, Dockerfile'ınıza aşağıdakini ekleyin:
RUN chmod 755 "runtimes/linux-x64/native/IronCefSubprocess"
Curtis Chau, Bilgisayar Bilimleri alanında Lisans Derecesine (Carleton Üniversitesi) sahip ve Node.js, TypeScript, JavaScript ve React konularında uzmanlaşmış ön uç geliştirmeyle ilgileniyor. Sezgisel ve estetik açıdan hoş kullanıcı arayüzleri oluşturma tutkunu, Curtis modern çerçevelerle çalışmayı ve iyi yapılandırılmış, görsel olarak çekici kılavuzlar oluşturmayı seviyor.