How to Run & Deploy IronPDF .NET on AWS Lambda

This article was translated from English: Does it need improvement?
Translated
View the article in English
class="container-fluid">
class="row">
class="col-md-2"> Amazon Web Services V1 related to How to Run & Deploy IronPDF .NET on AWS Lambda

1. Erstellen Sie AWS Lambda mit einer Container-Vorlage (.NET 5)

Bitte beachten Sie den ersten Teil dieses offiziellen Dokuments von AWS: .NET 5 AWS Lambda-Unterstützung mit Container-Bildern.

2. Paketabhängigkeiten hinzufügen

Diese Abhängigkeiten sind in dieser AWS-Umgebung für Chrome erforderlich.

Bitte ändern Sie die Docker-Datei entsprechend dieser Anweisungen:

AWS Lambda mit .NET 5

AWS Lambda with .NET 7

AWS Lambda with .NET 8

3. Add the IronPDF (Linux) NuGet package

Install IronPdf.Linux

  1. In Solution Explorer, right-click References, Manage NuGet Packages.
  2. Select Browse and search IronPdf.Linux.
  3. Select the package and install.

4. Modify FunctionHandler code

This example will create a PDF file from a webpage https://ironpdf.com/ and save it to /tmp. To view this PDF, you must upload it to another service such as S3.

It is necessary to configure the temporary folder when using IronPDF on AWS Lambda. Please use the TempFolderPath and CustomDeploymentDirectory properties to do this.

public Casing FunctionHandler(string input, ILambdaContext context)
{
    try
    {
        context.Logger.LogLine($"START FunctionHandler RequestId: {context.AwsRequestId} Input: {input}");

        var awsTmpPath = @"/tmp/"; // AWS temporary storage location

        // [Optional] Enable logging for debugging
        // Uncomment these lines if you encounter issues
        // IronPdf.Logging.Logger.EnableDebugging = true;
        // IronPdf.Logging.Logger.LogFilePath = awsTmpPath;
        // IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;

        // Set your IronPDF license key
        IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY";

        // Disable GPU for Chrome rendering in headless environments
        IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled;

        // Configure IronPDF to use the AWS temporary directory
        IronPdf.Installation.TempFolderPath = awsTmpPath;
        IronPdf.Installation.CustomDeploymentDirectory = awsTmpPath;

        // Automatically configure Linux and Docker dependencies
        IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true;

        context.Logger.LogLine($"Creating IronPdf.ChromePdfRenderer");
        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"; // Save file to /tmp

        context.Logger.LogLine($"Saving PDF with name: {fileName}");
        pdfDoc.SaveAs(fileName);

        // Place for future code to upload the PDF file to a service like AWS S3.

        context.Logger.LogLine($"COMPLETE!");
    }
    catch (Exception e)
    {
        context.Logger.LogLine($"[ERROR] FunctionHandler : {e.Message}");
    }

    return new Casing(input?.ToLower(), input?.ToUpper());
}
public Casing FunctionHandler(string input, ILambdaContext context)
{
    try
    {
        context.Logger.LogLine($"START FunctionHandler RequestId: {context.AwsRequestId} Input: {input}");

        var awsTmpPath = @"/tmp/"; // AWS temporary storage location

        // [Optional] Enable logging for debugging
        // Uncomment these lines if you encounter issues
        // IronPdf.Logging.Logger.EnableDebugging = true;
        // IronPdf.Logging.Logger.LogFilePath = awsTmpPath;
        // IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;

        // Set your IronPDF license key
        IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY";

        // Disable GPU for Chrome rendering in headless environments
        IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled;

        // Configure IronPDF to use the AWS temporary directory
        IronPdf.Installation.TempFolderPath = awsTmpPath;
        IronPdf.Installation.CustomDeploymentDirectory = awsTmpPath;

        // Automatically configure Linux and Docker dependencies
        IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true;

        context.Logger.LogLine($"Creating IronPdf.ChromePdfRenderer");
        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"; // Save file to /tmp

        context.Logger.LogLine($"Saving PDF with name: {fileName}");
        pdfDoc.SaveAs(fileName);

        // Place for future code to upload the PDF file to a service like AWS S3.

        context.Logger.LogLine($"COMPLETE!");
    }
    catch (Exception e)
    {
        context.Logger.LogLine($"[ERROR] FunctionHandler : {e.Message}");
    }

    return new Casing(input?.ToLower(), input?.ToUpper());
}
Public Function FunctionHandler(ByVal input As String, ByVal context As ILambdaContext) As Casing
	Try
		context.Logger.LogLine($"START FunctionHandler RequestId: {context.AwsRequestId} Input: {input}")

		Dim awsTmpPath = "/tmp/" ' AWS temporary storage location

		' [Optional] Enable logging for debugging
		' Uncomment these lines if you encounter issues
		' IronPdf.Logging.Logger.EnableDebugging = true;
		' IronPdf.Logging.Logger.LogFilePath = awsTmpPath;
		' IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;

		' Set your IronPDF license key
		IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY"

		' Disable GPU for Chrome rendering in headless environments
		IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled

		' Configure IronPDF to use the AWS temporary directory
		IronPdf.Installation.TempFolderPath = awsTmpPath
		IronPdf.Installation.CustomDeploymentDirectory = awsTmpPath

		' Automatically configure Linux and Docker dependencies
		IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = True

		context.Logger.LogLine($"Creating IronPdf.ChromePdfRenderer")
		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" ' Save file to /tmp

		context.Logger.LogLine($"Saving PDF with name: {fileName}")
		pdfDoc.SaveAs(fileName)

		' Place for future code to upload the PDF file to a service like AWS S3.

		context.Logger.LogLine($"COMPLETE!")
	Catch e As Exception
		context.Logger.LogLine($"[ERROR] FunctionHandler : {e.Message}")
	End Try

	Return New Casing(input?.ToLower(), input?.ToUpper())
End Function
$vbLabelText   $csharpLabel

5. Increase Memory and Timeout

IronPDF requires more time and memory than the default value of Lambda. You can configure it in aws-lambda-tools-defaults.json. Please adjust this to match your function. In this example, we will set it to 512 (MB) and 330 (seconds).

{
    "function-memory-size": 512,
    "function-timeout": 330
}

You also can update this configuration using the Lambda console. Navigate to the Configuring AWS Lambda functions article for more information.

6. Publish

Please follow the instructions in the latter part of the '.NET 5 AWS Lambda Support with Container Images' document to publish and test your Lambda function.

7. Try it out!

You can activate the Lambda function using the Lambda console or via Visual Studio by using the AWS Toolkit for Visual Studio.

Häufig gestellte Fragen

Wie erstelle ich ein PDF aus einer URL mit einer .NET AWS Lambda-Funktion?

Um ein PDF aus einer URL in einer .NET AWS Lambda-Funktion zu erstellen, verwenden Sie die ChromePdfRenderer.RenderUrlAsPdf-Methode von IronPDF. Stellen Sie sicher, dass der temporäre Ordner mit den Eigenschaften TempFolderPath und CustomDeploymentDirectory konfiguriert ist.

Welche Schritte sollte ich unternehmen, um IronPDF auf AWS Lambda zu konfigurieren?

Konfigurieren Sie IronPDF auf AWS Lambda, indem Sie die temporären Ordnerpfade mit TempFolderPath und CustomDeploymentDirectory einrichten, die GPU mit ChromeGpuModes.Disabled deaktivieren und die automatische Konfiguration von Linux- und Docker-Abhängigkeiten mit LinuxAndDockerDependenciesAutoConfig auf true aktivieren.

Warum ist es wichtig, die Speicher- und Timeout-Einstellungen für AWS Lambda anzupassen?

Die Anpassung der Speicher- und Timeout-Einstellungen für AWS Lambda ist wichtig, da IronPDF mehr Ressourcen erfordert als die Standardeinstellungen. Dies kann in aws-lambda-tools-defaults.json oder über die AWS Lambda-Konsole konfiguriert werden.

Wie stelle ich sicher, dass Chrome-Abhängigkeiten für AWS Lambda korrekt installiert sind?

Sorgen Sie dafür, dass Chrome-Abhängigkeiten ordnungsgemäß installiert werden, indem Sie die Dockerfile gemäß den Anweisungen für Ihre .NET-Version ändern, wie sie im Artikel bereitgestellt werden. Dazu gehört die Installation der erforderlichen Linux-Pakete für Chrome in der AWS-Umgebung.

Kann ich Visual Studio verwenden, um meine AWS Lambda-Funktion zu aktivieren und zu testen?

Ja, Sie können Visual Studio verwenden, um Ihre AWS Lambda-Funktion zu aktivieren und zu testen, indem Sie das AWS Toolkit für Visual Studio verwenden, das eine nahtlose Bereitstellung und Tests direkt aus der IDE ermöglicht.

Welche Bedeutung hat die Verwendung einer Container-Vorlage für .NET 5 auf AWS Lambda?

Die Verwendung einer Container-Vorlage für .NET 5 auf AWS Lambda ist bedeutend, da sie das Deployen von Anwendungen mit ihren Abhängigkeiten, wie IronPDF, erleichtert und für Konsistenz zwischen den Umgebungen sorgt.

Wie kann ich Ausnahmen in meiner AWS Lambda-Funktion mit IronPDF handhaben?

Behandeln Sie Ausnahmen in Ihrer AWS Lambda-Funktion, indem Sie Ihre IronPDF-Operationen in einem try-catch-Block einwickeln und Fehler mit context.Logger.LogLine zum Debuggen und zur Fehlerbehebung protokollieren.

Curtis Chau
Technischer Autor

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender ...

Weiterlesen
Bereit anzufangen?
Nuget Downloads 16,154,058 | Version: 2025.11 gerade veröffentlicht