質問編集履歴

3

インデントの修正

2019/09/20 06:27

投稿

tasuketeman
tasuketeman

スコア13

test CHANGED
File without changes
test CHANGED
@@ -56,9 +56,9 @@
56
56
 
57
57
  return
58
58
 
59
- except Exception as e:
59
+ except Exception as e:
60
60
 
61
- print(e)
61
+ print(e)
62
62
 
63
63
  ```
64
64
 
@@ -66,7 +66,7 @@
66
66
 
67
67
  ```
68
68
 
69
- "errorMessage": "Syntax error in module 'lambda_function'"
69
+ "Unable to import module 'lambda_function': No module named 'cv2'"
70
70
 
71
71
  ```]
72
72
 

2

インデントの修正

2019/09/20 06:27

投稿

tasuketeman
tasuketeman

スコア13

test CHANGED
File without changes
test CHANGED
@@ -18,21 +18,11 @@
18
18
 
19
19
  import io
20
20
 
21
-
22
-
23
21
  print('Loading function')
24
-
25
-
26
22
 
27
23
  s3 = boto3.client('s3')
28
24
 
29
-
30
-
31
-
32
-
33
25
  def lambda_handler(event, context):
34
-
35
-
36
26
 
37
27
  bucket = event['Records'][0]['s3']['bucket']['name']
38
28
 
@@ -42,39 +32,33 @@
42
32
 
43
33
  bucket = s3.Bucket(bucket) # ⑧バケットにアクセス
44
34
 
35
+ bucket.download_file(key, file_path)
36
+
45
37
  target_file=r"test/sample_test.txt"
46
38
 
47
39
  image_file=r"test/img_6252.jpg"
48
40
 
49
-
41
+ with open(target_file, 'rb') as f:
50
42
 
51
- withopen(target_file, 'rb') as f:
43
+ img_base64 = f.read()
52
44
 
53
- img_base64 = f.read()
45
+ img_binary = base64.b64decode(img_base64)
54
46
 
55
-
47
+ jpg=np.frombuffer(img_binary,dtype=np.uint8)
56
48
 
57
- img_binary = base64.b64decode(img_base64)
49
+ #raw image <- jpg
58
50
 
59
- jpg=np.frombuffer(img_binary,dtype=np.uint8)
51
+ img = cv2.imdecode(jpg, cv2.IMREAD_COLOR)
60
52
 
53
+ #画像を保存する場合
61
54
 
62
-
63
- #raw image <- jpg
64
-
65
- img = cv2.imdecode(jpg, cv2.IMREAD_COLOR)
66
-
67
- #画像を保存する場合
68
-
69
- cv2.imwrite(image_file,img)
55
+ cv2.imwrite(image_file,img)
70
56
 
71
57
  return
72
58
 
73
- except Exception as e:
59
+ except Exception as e:
74
60
 
75
- print(e)
61
+ print(e)
76
-
77
-
78
62
 
79
63
  ```
80
64
 
@@ -82,13 +66,7 @@
82
66
 
83
67
  ```
84
68
 
85
- "errorMessage": "Syntax error in module 'lambda_function': invalid syntax (lambda_function.py, line 21)",
69
+ "errorMessage": "Syntax error in module 'lambda_function'"
86
-
87
- "errorType": "Runtime.UserCodeSyntaxError",
88
-
89
- "stackTrace": [
90
-
91
- " File \"/var/task/lambda_function.py\" Line 21\n ta[rget_file=r\"test/sample_test.txt\"\n"
92
70
 
93
71
  ```]
94
72
 

1

インデント

2019/09/20 06:19

投稿

tasuketeman
tasuketeman

スコア13

test CHANGED
File without changes
test CHANGED
@@ -40,39 +40,35 @@
40
40
 
41
41
  try:
42
42
 
43
- bucket = s3.Bucket(bucket) # ⑧バケットにアクセス
43
+ bucket = s3.Bucket(bucket) # ⑧バケットにアクセス
44
44
 
45
- target_file=r"test/sample_test.txt"
45
+ target_file=r"test/sample_test.txt"
46
46
 
47
- image_file=r"test/img_6252.jpg"
47
+ image_file=r"test/img_6252.jpg"
48
48
 
49
49
 
50
50
 
51
- withopen(target_file, 'rb') as f:
51
+ withopen(target_file, 'rb') as f:
52
52
 
53
- img_base64 = f.read()
53
+ img_base64 = f.read()
54
54
 
55
55
 
56
56
 
57
- img_binary = base64.b64decode(img_base64)
57
+ img_binary = base64.b64decode(img_base64)
58
58
 
59
- jpg=np.frombuffer(img_binary,dtype=np.uint8)
59
+ jpg=np.frombuffer(img_binary,dtype=np.uint8)
60
60
 
61
61
 
62
62
 
63
- #raw image <- jpg
63
+ #raw image <- jpg
64
64
 
65
- img = cv2.imdecode(jpg, cv2.IMREAD_COLOR)
65
+ img = cv2.imdecode(jpg, cv2.IMREAD_COLOR)
66
66
 
67
- #画像を保存する場合
67
+ #画像を保存する場合
68
68
 
69
- cv2.imwrite(image_file,img)
69
+ cv2.imwrite(image_file,img)
70
70
 
71
-
72
-
73
-
74
-
75
- return
71
+ return
76
72
 
77
73
  except Exception as e:
78
74