LoginSignup
7
5

More than 1 year has passed since last update.

AWS Lambdaで.NET Core 3.1から.NET 6に移行したときにやったこと

Posted at

はじめに

AWS Lambdaで.NET6がサポートされました。ですが.Net Core 3.1のMicrosoftのサポート期限が2022/12/13まで、AWS Lambdaにおける.Net Core 3.1のランタイムサポートは2023/1/20までとなっており、.NET Core 3.1から.NET 6への移行が必要になりました。
やってみると、項目によってnet6.0だったりdotnet6だったりと、意外と紛らわしかったので忘れないようにメモしておきます。

やったこと

ターゲットフレームワークの変更

まずは言わずもがなですが、プロジェクトファイルのターゲットフレームワークを変更します。

***.csproj
-    <TargetFramework>netcoreapp3.1</TargetFramework>
+    <TargetFramework>net6.0</TargetFramework>

aws-lambda-tools-defaults.jsonの修正

AWS Toolkit for Visual Studioのテンプレートを使っている場合は、こちらのファイルがあるはずなので修正。

-   "framework": "netcoreapp3.1",
+   "framework": "net6.0",

function-runtimeを指定している場合は以下も修正が必要です。

-   "function-runtime": "dotnetcore3.1",
+   "function-runtime": "dotnet6",

SAMテンプレートの修正

SAMテンプレートを使っている場合は以下の通り修正します。

serverless.template
-         "Runtime": "dotnetcore3.1",
+         "Runtime": "dotnet6",

CodeBuildのImage変更

ビルドにCodeBuildを使っている場合は、Imageによってデフォルトでインストールされているランタイムが違います。詳しくは以下のURLを参照してください。
https://docs.aws.amazon.com/ja_jp/codebuild/latest/userguide/available-runtimes.html

以下はCloudformationテンプレートのCodeBuildの部分の差分です。

-         Image: aws/codebuild/amazonlinux2-x86_64-standard:3.0
+         Image: aws/codebuild/amazonlinux2-x86_64-standard:4.0

ちなみにImageを変えたくない場合は、.NET 6を手動でインストールすることで対応することもできます。以下のURLの「dotnet-install scripts」のリンクからインストール用のスクリプトをダウンロードし、CodeBuild上で実行することでインストールが可能です。

https://dotnet.microsoft.com/ja-jp/download/dotnet/6.0

buildspec.yml
chmod +x dotnet-install.sh
dotnet-install.sh -c 6.0
dotnet --info

Lambdaデプロイコマンドの修正

CodeBuildでlambdaのデプロイコマンドを使っている場合は、以下の通り修正します。

buildspec.yml
- dotnet lambda deploy-serverless --framework "netcoreapp3.1"
+ dotnet lambda deploy-serverless --framework "net6.0"

NSwag関連の修正

NSwagを利用している場合は、以下の部分を修正。

****.csproj
- 	<Exec Command="$(NSwagExe_Core31) run nswag.json /variables:ProjectPath=$(MSBuildProjectFullPath)" />
+ 	<Exec Command="$(NSwagExe_Net60) run nswag.json /variables:ProjectPath=$(MSBuildProjectFullPath)" />
nswag.json
-   "runtime": "NetCore31",
+   "runtime": "Net60",

NuGetパッケージの更新

.NET 6に対応していないバージョンがある場合は更新が必要です。

その他影響箇所の修正

以下のURLを参照し、該当箇所があれば修正。

https://learn.microsoft.com/ja-jp/aspnet/core/migration/31-to-60?view=aspnetcore-7.0&tabs=visual-studio

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5