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?

More than 3 years have passed since last update.

AWS Lambda Layersでsam buildを行うとファイルの階層が変わりimportエラーになる問題

Last updated at Posted at 2021-01-17

概要

sam deploy刷る前にsam buildをするだけでLambda Functionからimportできなくなってしまったので原因を調べました。

対象コード

Lambda Layer Template

Resources:
  SystemSharedLayer:
    Type: AWS::Serverless::LayerVersion
    Properties:
      ContentUri: src/layers/system_shared
      CompatibleRuntimes:
        - python3.8
    Metadata:
      BuildMethod: python3.8

Lambda Layer Src構造

src
└── layers
    └── system_shared
        ├── python
        │   └── hogehoge.py
        └── requirements.txt

呼び出し側

import hogehoge.py

Lamnda Function側での展開パス

sam buildしなかった場合

/opt
└── python/
    └── hogehoge.py

sam buildした場合

/opt
└── python/
    └── python/    ← 余計なパスが付与される
        └── hogehoge.py

解決策

仕様が一貫していないので諦めてtemplate側の階層指定を切り替える

Resources:
  SystemSharedLayer:
    Type: AWS::Serverless::LayerVersion
    Properties:
      ContentUri: src/layers/system_shared/python
      CompatibleRuntimes:
        - python3.8
    Metadata:
      BuildMethod: python3.8
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?