AWSラムダでIronPDF .NETを実行&デプロイする方法

This article was translated from English: Does it need improvement?
Translated
View the article in English
Amazon Web Services V1 related to AWSラムダでIronPDF .NETを実行&デプロイする方法

1. コンテナテンプレートでAWS Lambdaを作成する (.NET 5)

AWSによるこの公式ドキュメントの最初の部分を参照してください:.NET 5 AWS Lambdaコンテナイメージサポート

2. パッケージ依存関係の追加

これらの依存関係は、このAWS環境でのChromeのために必要です。

これらの指示に従ってDockerファイルを変更してください:

.NET 5を使用したAWS Lambda

AWS ラムダと.NET 7

</a

AWS Lambdaと.NET 8

</a

3.IronPdf (Linux) NuGetパッケージを追加する。

IronPdf.Linuxをインストールしてください。

1.ソリューション・エクスプローラで、[参照]を右クリックし、[NuGet パッケージの管理]を選択します。 2.ブラウズを選択し、IronPdf.Linuxを検索してください。

  1. パッケージを選択し、インストール。

4.FunctionHandlerコードを修正する。

この例では、ウェブページhttps://ironpdf.com/からPDFファイルを作成し、/tmpに保存します。 このPDFを表示するには、S3などの他のサービスにアップロードする必要があります。

IronPDF on AWS Lambdaを使用する際は、テンポラリフォルダを設定する必要があります。 そのためには、TempFolderPathCustomDeploymentDirectoryプロパティを使用してください。

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.メモリとタイムアウトを増やす

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メソッドを使用します。TempFolderPathCustomDeploymentDirectoryプロパティを使用して一時フォルダーを構成してください。

AWS LambdaでIronPDFを設定するためにどのような手順を取るべきですか?

AWS LambdaでIronPDFを設定するには、TempFolderPathCustomDeploymentDirectoryを使用して一時フォルダーパスを設定し、ChromeGpuModes.DisabledでGPUを無効にし、LinuxAndDockerDependenciesAutoConfigをtrueに設定してLinuxおよびDockerの依存関係を自動構成するようにします。

AWS Lambdaのメモリとタイムアウト設定を調整することが重要なのはなぜですか?

AWS Lambdaのメモリとタイムアウト設定を調整することは、IronPDFがデフォルト設定よりも多くのリソースを必要とするため重要です。これはaws-lambda-tools-defaults.jsonで構成するか、AWS Lambdaコンソールを通じて行うことができます。

AWS Lambda のために Chrome の依存関係が正しくインストールされていることを確認するにはどうすればよいですか?

記事に示されたあなたの.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関数で例外を処理します。

カーティス・チャウ
テクニカルライター

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

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はできましたか?
Nuget ダウンロード 16,685,821 | バージョン: 2025.12 リリース