質問編集履歴

7

エラー内容をさらに修正

2022/10/24 08:53

投稿

MaeharaKenji
MaeharaKenji

スコア86

test CHANGED
File without changes
test CHANGED
@@ -14,10 +14,6 @@
14
14
 
15
15
  どのように解消したらよいか教えて下さい。
16
16
 
17
-
18
- ```
19
- {"errorMessage": "An error occurred (ValidationException) when calling the Query operation: Query condition missed key schema element: sample_time", "errorType": "ClientError", "stackTrace": [" File \"/var/task/lambda_function.py\", line 17, in lambda_handler\n data = get_data()\n", " File \"/var/task/lambda_function.py\", line 8, in get_data\n response = table.query(\n", " File \"/var/runtime/boto3/resources/factory.py\", line 520, in do_action\n response = action(self, *args, **kwargs)\n", " File \"/var/runtime/boto3/resources/action.py\", line 83, in __call__\n response = getattr(parent.meta.client, operation_name)(*args, **params)\n", " File \"/var/runtime/botocore/client.py\", line 391, in _api_call\n return self._make_api_call(operation_name, kwargs)\n", " File \"/var/runtime/botocore/client.py\", line 719, in _make_api_call\n raise error_class(parsed_response, operation_name)\n"]}
20
- ```
21
17
 
22
18
  lambda単体でのテストの場合は次のような結果のエラー表示となります。
23
19
  ```ここに言語を入力

6

コード内容、エラー内容を修正

2022/10/24 08:51

投稿

MaeharaKenji
MaeharaKenji

スコア86

test CHANGED
File without changes
test CHANGED
@@ -39,7 +39,7 @@
39
39
  }
40
40
 
41
41
  Function Logs
42
- START RequestId: 956e3cc5-5766-49e5-b5c1-99cff24c29ba Version: $LATEST
42
+ START RequestId: 2ce0225c-18e2-4c98-a5e9-472a8968129b Version: $LATEST
43
43
  [ERROR] ClientError: An error occurred (ValidationException) when calling the Query operation: Query condition missed key schema element: sample_time
44
44
  Traceback (most recent call last):
45
45
    File "/var/task/lambda_function.py", line 17, in lambda_handler
@@ -53,11 +53,11 @@
53
53
    File "/var/runtime/botocore/client.py", line 391, in _api_call
54
54
      return self._make_api_call(operation_name, kwargs)
55
55
    File "/var/runtime/botocore/client.py", line 719, in _make_api_call
56
-     raise error_class(parsed_response, operation_name)END RequestId: 956e3cc5-5766-49e5-b5c1-99cff24c29ba
56
+     raise error_class(parsed_response, operation_name)END RequestId: 2ce0225c-18e2-4c98-a5e9-472a8968129b
57
- REPORT RequestId: 956e3cc5-5766-49e5-b5c1-99cff24c29ba Duration: 269.20 ms Billed Duration: 270 ms Memory Size: 128 MB Max Memory Used: 67 MB Init Duration: 358.61 ms
57
+ REPORT RequestId: 2ce0225c-18e2-4c98-a5e9-472a8968129b Duration: 286.93 ms Billed Duration: 287 ms Memory Size: 128 MB Max Memory Used: 67 MB Init Duration: 339.94 ms
58
58
 
59
59
  Request ID
60
- 956e3cc5-5766-49e5-b5c1-99cff24c29ba
60
+ 2ce0225c-18e2-4c98-a5e9-472a8968129b
61
61
  ```
62
62
 
63
63
 
@@ -72,7 +72,7 @@
72
72
 
73
73
  def get_data():
74
74
  response = table.query(
75
- KeyConditionExpression=Key('client_id').eq('send_data005'),
75
+ KeyConditionExpression=Key('client_id').eq('sample_time'),
76
76
  ScanIndexForward=False,
77
77
  Limit=1
78
78
  )

5

エラー内容を修正

2022/10/24 08:39

投稿

MaeharaKenji
MaeharaKenji

スコア86

test CHANGED
File without changes
test CHANGED
@@ -16,8 +16,7 @@
16
16
 
17
17
 
18
18
  ```
19
- gateway APIでテスト実行時の”レスポンス本文”でのエラー内容
20
- {"errorMessage": "list index out of range", "errorType": "IndexError", "stackTrace": [" File \"/var/task/lambda_function.py\", line 17, in lambda_handler\n data = get_data()\n", " File \"/var/task/lambda_function.py\", line 13, in get_data\n return response['Items'][0]\n"]}
19
+ {"errorMessage": "An error occurred (ValidationException) when calling the Query operation: Query condition missed key schema element: sample_time", "errorType": "ClientError", "stackTrace": [" File \"/var/task/lambda_function.py\", line 17, in lambda_handler\n data = get_data()\n", " File \"/var/task/lambda_function.py\", line 8, in get_data\n response = table.query(\n", " File \"/var/runtime/boto3/resources/factory.py\", line 520, in do_action\n response = action(self, *args, **kwargs)\n", " File \"/var/runtime/boto3/resources/action.py\", line 83, in __call__\n response = getattr(parent.meta.client, operation_name)(*args, **params)\n", " File \"/var/runtime/botocore/client.py\", line 391, in _api_call\n return self._make_api_call(operation_name, kwargs)\n", " File \"/var/runtime/botocore/client.py\", line 719, in _make_api_call\n raise error_class(parsed_response, operation_name)\n"]}
21
20
  ```
22
21
 
23
22
  lambda単体でのテストの場合は次のような結果のエラー表示となります。

4

エラー内容の修正

2022/10/24 08:38

投稿

MaeharaKenji
MaeharaKenji

スコア86

test CHANGED
File without changes
test CHANGED
@@ -27,26 +27,38 @@
27
27
 
28
28
  Response
29
29
  {
30
- "errorMessage": "list index out of range",
30
+ "errorMessage": "An error occurred (ValidationException) when calling the Query operation: Query condition missed key schema element: sample_time",
31
- "errorType": "IndexError",
31
+ "errorType": "ClientError",
32
32
  "stackTrace": [
33
33
  " File \"/var/task/lambda_function.py\", line 17, in lambda_handler\n data = get_data()\n",
34
- " File \"/var/task/lambda_function.py\", line 13, in get_data\n return response['Items'][0]\n"
34
+ " File \"/var/task/lambda_function.py\", line 8, in get_data\n response = table.query(\n",
35
+ " File \"/var/runtime/boto3/resources/factory.py\", line 520, in do_action\n response = action(self, *args, **kwargs)\n",
36
+ " File \"/var/runtime/boto3/resources/action.py\", line 83, in __call__\n response = getattr(parent.meta.client, operation_name)(*args, **params)\n",
37
+ " File \"/var/runtime/botocore/client.py\", line 391, in _api_call\n return self._make_api_call(operation_name, kwargs)\n",
38
+ " File \"/var/runtime/botocore/client.py\", line 719, in _make_api_call\n raise error_class(parsed_response, operation_name)\n"
35
39
  ]
36
40
  }
37
41
 
38
42
  Function Logs
39
- START RequestId: de9932b1-621a-4c6b-a55d-813b22e56ca1 Version: $LATEST
43
+ START RequestId: 956e3cc5-5766-49e5-b5c1-99cff24c29ba Version: $LATEST
40
- [ERROR] IndexError: list index out of range
44
+ [ERROR] ClientError: An error occurred (ValidationException) when calling the Query operation: Query condition missed key schema element: sample_time
41
45
  Traceback (most recent call last):
42
46
    File "/var/task/lambda_function.py", line 17, in lambda_handler
43
47
      data = get_data()
44
-   File "/var/task/lambda_function.py", line 13, in get_data
48
+   File "/var/task/lambda_function.py", line 8, in get_data
49
+     response = table.query(
50
+   File "/var/runtime/boto3/resources/factory.py", line 520, in do_action
51
+     response = action(self, *args, **kwargs)
52
+   File "/var/runtime/boto3/resources/action.py", line 83, in __call__
53
+     response = getattr(parent.meta.client, operation_name)(*args, **params)
54
+   File "/var/runtime/botocore/client.py", line 391, in _api_call
55
+     return self._make_api_call(operation_name, kwargs)
56
+   File "/var/runtime/botocore/client.py", line 719, in _make_api_call
45
-     return response['Items'][0]END RequestId: de9932b1-621a-4c6b-a55d-813b22e56ca1
57
+     raise error_class(parsed_response, operation_name)END RequestId: 956e3cc5-5766-49e5-b5c1-99cff24c29ba
46
- REPORT RequestId: de9932b1-621a-4c6b-a55d-813b22e56ca1 Duration: 163.68 ms Billed Duration: 164 ms Memory Size: 128 MB Max Memory Used: 68 MB
58
+ REPORT RequestId: 956e3cc5-5766-49e5-b5c1-99cff24c29ba Duration: 269.20 ms Billed Duration: 270 ms Memory Size: 128 MB Max Memory Used: 67 MB Init Duration: 358.61 ms
47
59
 
48
60
  Request ID
49
- de9932b1-621a-4c6b-a55d-813b22e56ca1
61
+ 956e3cc5-5766-49e5-b5c1-99cff24c29ba
50
62
  ```
51
63
 
52
64
 

3

コード内容の誤りを修正

2022/10/24 08:37

投稿

MaeharaKenji
MaeharaKenji

スコア86

test CHANGED
File without changes
test CHANGED
@@ -57,11 +57,11 @@
57
57
  from boto3.dynamodb.conditions import Key
58
58
 
59
59
  dynamodb = boto3.resource('dynamodb')
60
- table = dynamodb.Table('sensor_data')
60
+ table = dynamodb.Table('send_data005')
61
61
 
62
62
  def get_data():
63
63
  response = table.query(
64
- KeyConditionExpression=Key('client_id').eq('data_sender'),
64
+ KeyConditionExpression=Key('client_id').eq('send_data005'),
65
65
  ScanIndexForward=False,
66
66
  Limit=1
67
67
  )
@@ -71,6 +71,7 @@
71
71
  def lambda_handler(event, context):
72
72
  data = get_data()
73
73
  return data
74
+
74
75
 
75
76
  ```
76
77
 

2

エラー内容を追加。

2022/10/24 08:17

投稿

MaeharaKenji
MaeharaKenji

スコア86

test CHANGED
File without changes
test CHANGED
@@ -19,6 +19,36 @@
19
19
  gateway APIでテスト実行時の”レスポンス本文”でのエラー内容
20
20
  {"errorMessage": "list index out of range", "errorType": "IndexError", "stackTrace": [" File \"/var/task/lambda_function.py\", line 17, in lambda_handler\n data = get_data()\n", " File \"/var/task/lambda_function.py\", line 13, in get_data\n return response['Items'][0]\n"]}
21
21
  ```
22
+
23
+ lambda単体でのテストの場合は次のような結果のエラー表示となります。
24
+ ```ここに言語を入力
25
+ Test Event Name
26
+ test20221024
27
+
28
+ Response
29
+ {
30
+ "errorMessage": "list index out of range",
31
+ "errorType": "IndexError",
32
+ "stackTrace": [
33
+ " File \"/var/task/lambda_function.py\", line 17, in lambda_handler\n data = get_data()\n",
34
+ " File \"/var/task/lambda_function.py\", line 13, in get_data\n return response['Items'][0]\n"
35
+ ]
36
+ }
37
+
38
+ Function Logs
39
+ START RequestId: de9932b1-621a-4c6b-a55d-813b22e56ca1 Version: $LATEST
40
+ [ERROR] IndexError: list index out of range
41
+ Traceback (most recent call last):
42
+   File "/var/task/lambda_function.py", line 17, in lambda_handler
43
+     data = get_data()
44
+   File "/var/task/lambda_function.py", line 13, in get_data
45
+     return response['Items'][0]END RequestId: de9932b1-621a-4c6b-a55d-813b22e56ca1
46
+ REPORT RequestId: de9932b1-621a-4c6b-a55d-813b22e56ca1 Duration: 163.68 ms Billed Duration: 164 ms Memory Size: 128 MB Max Memory Used: 68 MB
47
+
48
+ Request ID
49
+ de9932b1-621a-4c6b-a55d-813b22e56ca1
50
+ ```
51
+
22
52
 
23
53
  ### 該当のソースコード
24
54
 

1

一部修正

2022/10/24 08:12

投稿

MaeharaKenji
MaeharaKenji

スコア86

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
  ```
19
- gateway APIで実行時のエラー内容
19
+ gateway APIでテスト実行時の”レスポンス本文”でのエラー内容
20
20
  {"errorMessage": "list index out of range", "errorType": "IndexError", "stackTrace": [" File \"/var/task/lambda_function.py\", line 17, in lambda_handler\n data = get_data()\n", " File \"/var/task/lambda_function.py\", line 13, in get_data\n return response['Items'][0]\n"]}
21
21
  ```
22
22