前提
Windows上で、terraformを使用
概要
Lambda構築の、引っ掛かりポイント
詳細
Code
Lambdaの部分のみ記載
module "lambda" {
source = "terraform-aws-modules/lambda/aws"
version = "7.2.1"
function_name = "function"
description = "lambda for example"
handler = "function.lambda_handler"
runtime = "python3.13"
attach_policy_json = true
policy_json = data.aws_iam_policy_document.policy.json
source_path = ["${path.module}/codes/function.py"]
timeout = 300
trigger_on_package_timestamp = false
create_lambda_function_url = true
tags = {
Environment = var.env
}
environment_variables = {
Token: module.secretsmanager.secret
}
layers = ["${aws_lambda_layer_version.lambda_layer.arn}"]
}
引っ掛かりポイント
terraform plan時にこんなエラーが出る
│ UnicodeDecodeError: 'cp932' codec can't decode byte 0xef in position 1540: illegal multibyte sequence
文字エンコーディングがデフォルトの cp932 なことが原因のエラー
文字エンコーディングを UTF-8 にするとエラーが解消される。
解消パターン
C:\Users\****\terraform\dev>set PYTHONUTF8=1
C:\Users\****\terraform\dev>terraform plan
## 途中結果は略
Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if
you run "terraform apply" now.
C:\Users\****\terraform\dev>terraform apply
## 途中結果は略
Apply complete! Resources: * added, * changed, * destroyed.
plan, apply両方うまくいくようになる