S3のバケット、"test"の中にエンコードされた画像テキストがtest/sample_test.txtの場所にあります。この画像をlambdaを動かしたときにデコードして別の名前で同じパス場所に保存したいのですがパス名の記述がイマイチわかりません。教えてください
python
1import json 2import urllib.parse 3import boto3 4import base64 5import io 6import cgi 7imgname ="hoge.png" 8print('Loading function') 9s3 = boto3.resource('s3') 10def lambda_handler(event, context): 11 bucket = event['Records'][0]['s3']['bucket']['name'] 12 key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8') 13 try: 14 bucket = s3.Bucket(bucket) # ⑧バケットにアクセス 15 #bucket.download_file(key,"test/sample_test.txt" ) 16 target_file=r"test/sample_test.txt" 17 #image_file=r"test/img_6252.jpg" 18 with open(target_file, 'rb') as f: 19 img_base64 = f.read() 20 img_binary = base64.b64decode(img_base64) 21 f=open(imgname, "wb") 22 f.close() 23 return 24 except Exception as e: 25
エラーメッセージ
[Errno 2] No such file or directory: 'test/sample_test.txt'
あなたの回答
tips
プレビュー