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 でPillowを利用でこまった話

Last updated at Posted at 2020-09-03

背景

Python のPillow を利用したLambda FunctionをLocalでは問題なく実行できるのにcdkでDeployしたら以下
のようまエラーではまってました。

cannot import name '_imaging' from 'PIL' (/var/task/PIL/__init__.py)

最初にDeployした方法(エラー再現パタン)

  • cdk の指定
create_func = lambda.Function(self, "createFunction",
                               code=lambda.Code.asset('functions/artifacts'),
                               handler="create.lambda_handler",
                               runtime=lambda.Runtime.PYTHON_3_8,
                               environment=environment,
                               tracing=lambda.Tracing.ACTIVE,
                               timeout=core.Duration.seconds(29),
                               memory_size=512
                             )

  • Deploy コマンド
$ rm -rf functions/artifacts
$ cp -a functions/src functions/artifacts
$ pip install -r functions/artifacts/requirements.txt -t functions/artifacts/
$ cdk deploy --require-approval never 

成功パタン以下の方法で対応できた

  • cdk の指定
create_func = lambda.Function(self, "createFunction",
                                           code=lambda.Code.from_asset('functions/src',
                                              bundling=core.BundlingOptions(
                                                 image=lambda.Runtime.PYTHON_3_8.bundling_docker_image,
                                                 command=[ 'bash', '-c', 'pip install -r requirements.txt -t /asset-output && cp -a . /asset-output'],
                                              )
                                           ),
                                           handler="create.lambda_handler",
                                           runtime=lambda.Runtime.PYTHON_3_8,
                                           environment=environment,
                                           tracing=lambda.Tracing.ACTIVE,
                                           timeout=core.Duration.seconds(
                                               29),
                                           memory_size=512
                                           )

  • Deploy コマンド
$ cdk deploy --require-approval never 

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?