AWS Lambda IronPDF Amazon Linux 2에서 사용
AWS Lambda / Amazon Linux 2 ( IronPdf.Linux를 사용하여 관리자/루트 권한으로 설치)
이 정보는 저희 웹사이트( AWS Lambda IronPDF 가이드) 에도 나와 있습니다.
AWS 지침
- 컨테이너 이미지를 사용한 AWS .NET 5 Lambda 지원을 참조하세요.
- 다음 Dockerfile을 생성하고 사용하십시오.
# Use the .NET 5 AWS Lambda runtime as the base image
FROM public.ecr.aws/lambda/dotnet:5.0
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" .
- 솔루션에 IronPdf.Linux 패키지를 추가하세요.
_FunctionHandler코드를 수정합니다 - 이 예제는 웹 페이지(IronPDF)에서 PDF를 생성하고/tmp에 저장합니다. 이 PDF 파일을 보려면 S3와 같은 다른 서비스에 업로드해야 합니다. (AWS 공식 예제는 여기에서 확인할 수 있습니다 - AWS S3 기본 사항 )
// 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 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)
- 메모리 및 타임아웃 늘리기 - IronPDF Lambda의 기본값보다 더 많은 시간과 메모리를 필요로 합니다. 이는
aws-lambda-tools-defaults.json에서 구성할 수 있습니다. 함수의 요구 사항에 맞게 이 값들을 조정하십시오.
이 예시에서는 크기를 512MB, 시간을 330초로 설정했습니다.
"function-memory-size": 512,
"function-timeout": 330,
Lambda 콘솔( AWS Lambda 메모리 구성) 을 사용해서도 구성을 업데이트할 수 있습니다.
- AWS .NET 5 Lambda 컨테이너 이미지 지원에 대한 문서의 마지막 부분을 참조하여 Lambda 함수를 게시하고 테스트해 보세요.
- Lambda 함수는 Lambda 콘솔, AWS Lambda 콘솔을 사용하거나 AWS Toolkit for Visual Studio를 사용하여 Visual Studio를 통해 호출할 수도 있습니다.
"GPU 프로세스를 사용할 수 없습니다"라는 메시지가 표시되면 설치가 관리자 권한으로 실행되지 않았을 수 있습니다. 관리자/루트 권한으로 소프트웨어를 다시 실행해 보세요. 또는 Dockerfile에 다음 내용을 추가하세요.
RUN chmod 755 "runtimes/linux-x64/native/IronCefSubprocess"

