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 5 years have passed since last update.

[zappa + boto3 + rekognition DetectLabels]で KeyError: 'Instances'

Last updated at Posted at 2019-07-18

zappaでlambdaデプロイしたら、rekognition DetectLabelsのレスポンスがローカル環境と変わってハマった。

解決方法

  1. デプロイパッケージにboto3を含める。(zappa deployするディレクトリでpip install boto3 -t .)

  2. zappa_settings.jsonを

zappa_settings.json
{
    "dev": {
        "app_function": "your_app.app",
        "aws_region": "your_region",
        "profile_name": "your_profile_name",
        "project_name": "your_project_name",
        "runtime": "python3.6",
        "s3_bucket": "your_s3_backet",
        "exclude": ["/var/runtime/boto*"] //追加
}
}

にする。

原因

lambda内にデフォルトで搭載されているboto3のバージョンが古いことが原因らしい。
(バージョンによってDetectLabelsのレスポンスが若干違うっぽい)

zappaのドキュメント曰く、

By default, Zappa will exclude Boto, because it's already available in the Lambda execution environment.

"exclude": [".gz", ".rar"], // A list of regex patterns to exclude from the archive. To exclude boto3 and botocore (available in an older version on Lambda), add "boto3*" and "botocore*".

とのことなので、デフォルト搭載のboto3を呼ばれないようにする。

cloud watch logを追うと、Loading JSON file: /var/runtime/botocore/data/endpoints.jsonとあったので、"exclude": ["/var/runtime/boto*"]を追加した。

"exclude": ["*.a"]でもいけた。

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?