0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

terraform-aws-modules/lambda/awsとPoetryを使ってLambda Layerを作成

Posted at

課題

Terraformの terraform-aws-modules/lambda/awspoetry を利用してLambda Layerを作成したい場合の方法です。

基本はドキュメントの例にあるように create_layer = true を設定すれば良いのですが、そのままドキュメント通りに実装すると、Unable to import module となります。

これは、こちらに記載のある python ディレクトリ配下にモジュールをインストールする構造を実現できません。

実現方法

poetry_install と一緒に、prefix_in_zip = "python" とするとLambda Layerとして以下のように定義すると、Layerのモジュールをインポートして利用できるようになります。

.
├── package
│   ├── poetry.lock
│   ├── pyproject.toml
└── layer
    └── main.tf
module "layer" {
  source  = "terraform-aws-modules/lambda/aws"
  version = "6.5.0"


  layer_name   = "layer-name"
  runtime      = "python3.11"
  description  = "Layer"
  create_layer = true

  source_path = [
    {
      path           = "${path.module}/../package"
      poetry_install = true
      prefix_in_zip  = "python"
    }
  ]
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?