LoginSignup
3
3

More than 5 years have passed since last update.

Lambda pythonから S3 にアクセスできない?

Posted at

やりたいこと

  1. S3にデータがアップされたらSNSからVPC内のLambdaを起動
  2. 起動したLambdaにてアップされたデータをS3から取得し、内容をパース
  3. パースした内容を ElasticSearchにインサート

問題点

2.の手順でLambdaからS3にアクセスしようと思ったら、以下のエラーが発生

Exception (<class 'boto3.exceptions.ResourceNotExistsError'>) : The 's3' resource does not exist.
The available resources are:

確認内容

  1. S3へのPutイベントでSNSをPublishし、Lambdaが起動することはOK
  2. VPC内のLambdaから外部のサーバにアクセスできることはOK
  3. Lambdaにてimport boto3、import botocore もエラーなくOK
  4. でも、boto3のresourceなどでアクセスすると、s3 resourceは存在しないって怒られる。

確認のため、boto3で ec2 resourceをアクセスしにいったら同様に ec3 resouceは存在しないと怒られる。

boto3がおかしい?

Lambda Functionをデプロイする際、必要なパッケージをダウンロードしてzipでアップしている。この時、きちんとboto3、botocore両方とも以下のコマンドで含めている。

pip install boto3 -t .

もしかして、Lambda Function内のboto3がおかしい??

やったこと

試しに、Lambda Functionパッケージ内から boto3とbotocoreを
削除する。

削除した状態で Lmabda FunctionをDeployし、S3にファイルをアップロード。すると、SNS経由でLambdaに通知されたS3のKeyからデータを取得することに成功。

boto3をzipに含めたことが原因だったようです。。

参考

3
3
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
3
3