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
Amazon Web Services V1 related to How to Run & Deploy IronPDF .NET on AWS Lambda

1. Create AWS Lambda with a container template (.NET 5)

Please refer to the first part of this official document from AWS: .NET 5 AWS Lambda Support with Container Images.

2. Add package dependencies

These dependencies are required for Chrome in this AWS environment.

Please modify the Docker file according to these instructions:

AWS Lambda with .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.

Preguntas Frecuentes

¿Cómo creo un PDF desde una URL usando una función .NET AWS Lambda?

Para crear un PDF desde una URL en una función .NET AWS Lambda, use el método ChromePdfRenderer.RenderUrlAsPdf de IronPDF. Asegúrese de que la carpeta temporal esté configurada usando las propiedades TempFolderPath y CustomDeploymentDirectory.

¿Qué pasos debo seguir para configurar IronPDF en AWS Lambda?

Configure IronPDF en AWS Lambda estableciendo las rutas de carpetas temporales usando TempFolderPath y CustomDeploymentDirectory, deshabilitando la GPU con ChromeGpuModes.Disabled y habilitando la configuración automática de dependencias de Linux y Docker con LinuxAndDockerDependenciesAutoConfig establecido en true.

¿Por qué es importante ajustar la memoria y las configuraciones de tiempo de espera para AWS Lambda?

Ajustar la memoria y las configuraciones de tiempo de espera para AWS Lambda es crucial porque IronPDF requiere más recursos que las configuraciones predeterminadas. Esto se puede configurar en aws-lambda-tools-defaults.json o a través de la consola de AWS Lambda.

¿Cómo aseguro que las dependencias de Chrome estén correctamente instaladas para AWS Lambda?

Asegúrese de que las dependencias de Chrome estén correctamente instaladas modificando el Dockerfile de acuerdo con las instrucciones específicas para su versión de .NET, tal como se proporciona en el artículo. Esto incluye la instalación de los paquetes de Linux necesarios para Chrome en el entorno AWS.

¿Puedo usar Visual Studio para activar y probar mi función AWS Lambda?

Sí, puede usar Visual Studio para activar y probar su función AWS Lambda utilizando AWS Toolkit para Visual Studio, que permite una implementación y prueba sin problemas directamente desde el IDE.

¿Cuál es la importancia de utilizar una plantilla de contenedor para .NET 5 en AWS Lambda?

Usar una plantilla de contenedor para .NET 5 en AWS Lambda es importante porque facilita el despliegue de aplicaciones con sus dependencias, como IronPDF, asegurando la consistencia en los entornos.

¿Cómo puedo manejar excepciones en mi función AWS Lambda usando IronPDF?

Maneje excepciones en su función AWS Lambda envolviendo sus operaciones de IronPDF en un bloque try-catch, registrando errores utilizando context.Logger.LogLine para depuración y resolución de problemas.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado