File tree 4 files changed +12
-4
lines changed
4 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ deps:
117
117
poetry install
118
118
119
119
integration :
120
- sam local invoke ProductEventHandler --event ./__tests__ /events/update.json
120
+ sam local invoke ProductEventHandler --event ./tests/resources /events/update.json
121
121
122
122
venv :
123
123
@if [ -d " ./.venv" ]; then echo " $( red) .venv already exists, not continuing!$( sgr0) " ; exit 1; fi
Original file line number Diff line number Diff line change 1
1
import logging
2
2
import json
3
+ import asyncio
3
4
from typing import Dict
4
5
from src .product .product_service import receive_product_update
5
6
logger = logging .getLogger (__name__ )
8
9
# Actual lambda handler, responsible for extracting message from SNS
9
10
# and dealing with lambda-related things, passing the encoded message along to the
10
11
# message handler
11
- async def handler (event : Dict ):
12
+ async def handler (event : Dict , context ):
12
13
logger .info (f'{ event = } ' )
13
14
14
15
# Read the SNS message and pass the contents to the actual message handler
@@ -19,3 +20,10 @@ async def handler(event: Dict):
19
20
20
21
# Return the current size of the repository
21
22
return len (results .keys ())
23
+
24
+ def lambda_handler (event , context ):
25
+ loop = asyncio .get_event_loop ()
26
+ # DynamoDB resource defined above is attached to this loop:
27
+ # if you use asyncio.run instead
28
+ # you will encounter "Event loop closed" exception
29
+ return loop .run_until_complete (handler (event , context ))
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ Resources:
27
27
Properties :
28
28
Description : A Lambda function that receives a Product update event from the ProductEvent topic
29
29
Runtime : python3.11
30
- Handler : src.lambda .product.handler
30
+ Handler : src._lambda .product.lambda_handler
31
31
# This property associates this Lambda function with the SNS topic defined above, so that whenever the topic
32
32
# receives a message, the Lambda function is invoked
33
33
Events :
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ async def test_lambda_consumes_a_valid_sns_event(mocker):
20
20
payload = json .load (f )
21
21
22
22
# (2) Act: call the actual lambda with a valid SNS message
23
- result = await product .handler (payload )
23
+ result = await product .handler (payload , {} )
24
24
25
25
# (3) Assert: should return
26
26
assert result == num_products + 1
You can’t perform that action at this time.
0 commit comments