AWSラムダでIronPDF .NETを実行&デプロイする方法
1. コンテナテンプレートでAWS Lambdaを作成する (.NET 5)
AWSによるこの公式ドキュメントの最初の部分を参照してください:.NET 5 AWS Lambdaコンテナイメージサポート。
2. パッケージ依存関係の追加
これらの依存関係は、このAWS環境でのChromeのために必要です。
これらの指示に従ってDockerファイルを変更してください:
.NET 5を使用したAWS Lambda
AWS ラムダと.NET 7
AWS Lambdaと.NET 8
3.IronPDF (Linux) NuGetパッケージを追加する
IronPdf.Linuxをインストールします
1.ソリューション・エクスプローラで、[参照]を右クリックし、[NuGet パッケージの管理]を選択します。
2. 閲覧を選択し、IronPdf.Linuxを検索します。
3. パッケージを選択し、インストール。
4.FunctionHandlerコードを修正する
この例では、ウェブページhttps://ironpdf.com/からPDFファイルを作成し、/tmpに保存します。 このPDFを表示するには、S3などの他のサービスにアップロードする必要があります。
IronPDF on AWS Lambdaを使用する際は、テンポラリフォルダを設定する必要があります。 そのためには、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 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 Function5.メモリとタイムアウトを増やす
IronPDFはLambdaのデフォルト値よりも多くの時間とメモリを必要とします。 それをaws-lambda-tools-defaults.jsonで設定することができます。 あなたの機能に合わせて調整してください。 この例では、512(MB)と330(秒)に設定します。
{
"function-memory-size": 512,
"function-timeout": 330
}
また、Lambdaコンソールを使用して、この設定を更新することもできます。 詳細については、Configuring AWS Lambda functions の記事を参照してください。
6.公開する
.NET 5 AWS Lambda Support with Container Images' ドキュメントの後半の指示に従って、Lambda 関数を公開してテストしてください。
7.試してみてください
Lambdaコンソールを使用するか、AWS Toolkit for Visual Studioを使用してVisual Studio経由でLambda関数を有効にすることができます。
よくある質問
.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のメモリとタイムアウト設定を調整することが重要なのはなぜですか?
AWS Lambdaのメモリとタイムアウト設定を調整することは、IronPDFがデフォルト設定よりも多くのリソースを必要とするため重要です。これはaws-lambda-tools-defaults.jsonで構成するか、AWS Lambdaコンソールを通じて行うことができます。
AWS Lambda のために Chrome の依存関係が正しくインストールされていることを確認するにはどうすればよいですか?
記事に示されたあなた for .NETバージョンに特有の指示に従ってDockerfileを修正することで、AWS環境でChromeに必要なLinuxパッケージをインストールすることを含め、Chrome依存関係が正しくインストールされていることを確認します。
Visual Studio を使用して AWS Lambda 関数をアクティブ化してテストできますか?
はい、Visual StudioのAWS Toolkitを使用して、シームレスにIDEから直接デプロイとテストを実行することにより、AWS Lambda関数を有効にし、テストすることができます。
.NET 5のAWS Lambda用コンテナテンプレートを使用する意義は何ですか?
.NET 5のAWS Lambda用コンテナテンプレートを使用することは、IronPDFなどの依存関係とともにアプリケーションをデプロイすることを容易にし、環境間の一貫性を確保するため重要です。
AWS Lambda関数でIronPDFを使用して例外をどのように処理しますか?
IronPDF操作をtry-catchブロックで囲み、context.Logger.LogLineを使用してエラーを記録してデバッグおよびトラブルシューティングすることで、AWS Lambda関数で例外を処理します。
How can I ensure my Docker dependencies are correctly configured for IronPDF?
IronPDF offers an automatic configuration for Linux and Docker dependencies using IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig. Enabling this option helps manage dependencies efficiently in a dockerized AWS Lambda environment.
What are the steps for building and deploying a function with IronPDF on AWS?
To build and deploy a function with IronPDF on AWS, use `dotnet lambda deploy-function` to create a Docker image, push it to Amazon ECR, and deploy your function. Follow AWS’s deployment guide for a complete workflow from building to testing.
Can I use AWS S3 with IronPDF for storing generated PDFs?
Yes, after generating PDFs using IronPDF on AWS Lambda, you can upload them to AWS S3 for storage. This typically involves using AWS SDK or other tools to transfer files from Lambda’s temporary storage to S3.

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。