AWS Lambda에서 IronPDF .NET을 실행 및 배포하는 방법
1. 컨테이너 템플릿(.NET 5)을 사용하여 AWS Lambda를 생성합니다.
AWS에서 제공하는 공식 문서인 "컨테이너 이미지를 사용한 .NET 5 AWS Lambda 지원" 의 첫 번째 부분을 참조하십시오.
2. 패키지 종속성 추가
이러한 종속성은 이 AWS 환경에서 Chrome을 사용하는 데 필요합니다.
다음 지침에 따라 Docker 파일을 수정하십시오.
.NET 5를 사용한 AWS Lambda
.NET 7을 사용한 AWS Lambda
.NET 8을 사용한 AWS Lambda
3. IronPDF(Linux) NuGet 패키지를 추가합니다.
설치하세요 IronPdf.Linux
- 솔루션 탐색기에서 참조를 마우스 오른쪽 버튼으로 클릭하고 NuGet 패키지 관리를 선택합니다.
- 탐색을 선택하고 검색하세요
IronPdf.Linux. - 패키지를 선택하고 설치하세요.
4. FunctionHandler 코드 수정
이 예제는 웹 페이지에서 PDF 파일을 생성하고 https://ironpdf.com/에 저장합니다 /tmp. 이 PDF 파일을 보려면 S3와 같은 다른 서비스에 업로드해야 합니다.
AWS Lambda에서 IronPDF를 사용할 때는 임시 폴더를 구성해야 합니다. 이를 위해서는 TempFolderPath 및 CustomDeploymentDirectory 속성을 사용하십시오.
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
5. 메모리 및 타임아웃 증가
IronPDF는 Lambda의 기본값보다 더 많은 시간과 메모리를 필요로 합니다. 구성할 수 있습니다 aws-lambda-tools-defaults.json. 사용하시는 기능에 맞게 이 값을 조정해 주세요. 이 예시에서는 값을 512MB, 시간을 330초로 설정하겠습니다.
{
"function-memory-size": 512,
"function-timeout": 330
}
Lambda 콘솔을 사용하여 이 구성을 업데이트할 수도 있습니다. 자세한 내용은 AWS Lambda 함수 구성 문서를 참조하세요.
6. 게시
Lambda 함수를 게시하고 테스트하려면 ' 컨테이너 이미지를 사용한 .NET 5 AWS Lambda 지원 ' 문서의 뒷부분에 있는 지침을 따르십시오.
7. 직접 시도해 보세요!
Lambda 함수는 Lambda 콘솔을 사용하거나 AWS Toolkit for Visual Studio를 사용하여 Visual Studio를 통해 활성화할 수 있습니다.
자주 묻는 질문
.NET AWS Lambda 함수를 사용하여 URL에서 PDF를 생성하는 방법은 무엇인가요?
.NET AWS Lambda 함수에서 URL을 사용하여 PDF를 생성하려면 IronPDF의 ChromePdfRenderer.RenderUrlAsPdf 메서드를 사용하십시오. TempFolderPath 및 CustomDeploymentDirectory 속성을 사용하여 임시 폴더가 구성되었는지 확인하십시오.
AWS Lambda에서 IronPDF를 구성하려면 어떤 단계를 거쳐야 하나요?
AWS Lambda에서 IronPDF를 구성하려면 TempFolderPath 및 CustomDeploymentDirectory 사용하여 임시 폴더 경로를 설정하고, ChromeGpuModes.Disabled 를 사용하여 GPU를 비활성화하고, LinuxAndDockerDependenciesAutoConfig 를 true로 설정하여 Linux 및 Docker 종속성의 자동 구성을 활성화하십시오.
AWS Lambda에서 메모리 및 타임아웃 설정을 조정하는 것이 중요한 이유는 무엇입니까?
IronPDF는 기본 설정보다 더 많은 리소스를 필요로 하므로 AWS Lambda의 메모리 및 타임아웃 설정을 조정하는 것이 중요합니다. 이 설정은 aws-lambda-tools-defaults.json 또는 AWS Lambda 콘솔을 통해 구성할 수 있습니다.
AWS Lambda에 필요한 Chrome 종속성이 올바르게 설치되었는지 어떻게 확인할 수 있나요?
문서에 제공된 .NET 버전별 지침에 따라 Dockerfile을 수정하여 Chrome 종속성이 올바르게 설치되었는지 확인하십시오. 여기에는 AWS 환경에 Chrome에 필요한 Linux 패키지를 설치하는 작업이 포함됩니다.
Visual Studio를 사용하여 AWS Lambda 함수를 활성화하고 테스트할 수 있습니까?
네, Visual Studio용 AWS 툴킷을 사용하면 Visual Studio에서 AWS Lambda 함수를 활성화하고 테스트할 수 있습니다. 이를 통해 IDE에서 바로 원활하게 배포 및 테스트할 수 있습니다.
AWS Lambda에서 .NET 5용 컨테이너 템플릿을 사용하는 것의 의미는 무엇인가요?
AWS Lambda에서 .NET 5용 컨테이너 템플릿을 사용하는 것은 IronPDF와 같은 종속성을 포함한 애플리케이션 배포를 용이하게 하여 환경 간 일관성을 보장하기 때문에 중요합니다.
IronPDF를 사용하여 AWS Lambda 함수에서 예외를 처리하는 방법은 무엇인가요?
AWS Lambda 함수에서 예외를 처리하려면 IronPDF 작업을 try-catch 블록으로 감싸고, 디버깅 및 문제 해결을 위해 context.Logger.LogLine 사용하여 오류를 로깅하십시오.

