🤖

cfnresponseはあります

に公開

AWSのCloudFormationでカスタムリソースをLambdaで作るときにcfnresponseを使おうとするとインポートエラー Unable to import module 'index': No module named 'cfnresponse' が出ることがある。

こんな書き方だとエラーになる。

import boto3, cfnresponse

ドキュメントをちゃんと読むと、 import cfnresponse だけにしろと書いてある。

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-lambda-function-code-cfnresponsemodule.html

Use this exact import statement. If you use other variants of the import statement, CloudFormation doesn't include the response module.

なので、上記を書き換えてこうするとcfnresponseが読み込まれてエラーにならなくなる。

import boto3
import cfnresponse

Discussion