[Terraform] Lambda Web Functions (Python) を構築する

2026-11-29
Lambda Web Functions を Terraform で構築します。

ランタイムは Python 3.15 にしました。
こちらは現在プレビュー中です。使用の際はご注意ください。
Links
コード
</>
1
メモ
auth_type は ApplicationManaged にしてます
ウェブフレームワークとして FastAPI を使います。

なお Event Fucntions と同様に、ビルドパッケージ (zip) には FastAPI のソースコードを含める必要があります。
ビルド
Lambda 関数のビルドパッケージを作成します。
コマンドを実行すると zip ファイルが出来上がります。
cd lambdaweb
uv pip install . --target package --python-platform aarch64-manylinux2014 --python-version 3.15 --only-binary=:all: --no-binary app
cd package && zip -r ../package.zip . && cd ../../
構築
Terraform でリソースを作成します。
$ echo 'identifier = "test20261129"' > terraform.tfvars
$ terraform init
plan します
$ terraform plan | grep will
Terraform will perform the following actions:
  # archive_file.code will be created
  # aws_iam_role.lambdaweb_execution will be created
  # aws_iam_role_policy_attachment.lambdaweb_execution_logs will be created
  # aws_lambdaweb_function.main will be created
  # aws_lambdaweb_function_endpoint.main will be created
  # aws_lambdaweb_function_revision.main will be created
  # aws_s3_bucket.lambdaweb_code will be created
  # aws_s3_bucket_policy.lambdaweb_code will be created
  # aws_s3_bucket_versioning.lambdaweb_code will be created
  # aws_s3_object.code will be created
apply します
$ terraform apply
構築できました。
screated.png screated.png
動作確認
GET /hello を叩きます
sgethello.png sgethello.png