File tree Expand file tree Collapse file tree 4 files changed +12
-4
lines changed
Expand file tree Collapse file tree 4 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ deps:
117117 poetry install
118118
119119integration :
120- sam local invoke ProductEventHandler --event ./__tests__ /events/update.json
120+ sam local invoke ProductEventHandler --event ./tests/resources /events/update.json
121121
122122venv :
123123 @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 11import logging
22import json
3+ import asyncio
34from typing import Dict
45from src .product .product_service import receive_product_update
56logger = logging .getLogger (__name__ )
89# Actual lambda handler, responsible for extracting message from SNS
910# and dealing with lambda-related things, passing the encoded message along to the
1011# message handler
11- async def handler (event : Dict ):
12+ async def handler (event : Dict , context ):
1213 logger .info (f'{ event = } ' )
1314
1415 # Read the SNS message and pass the contents to the actual message handler
@@ -19,3 +20,10 @@ async def handler(event: Dict):
1920
2021 # Return the current size of the repository
2122 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:
2727 Properties :
2828 Description : A Lambda function that receives a Product update event from the ProductEvent topic
2929 Runtime : python3.11
30- Handler : src.lambda .product.handler
30+ Handler : src._lambda .product.lambda_handler
3131 # This property associates this Lambda function with the SNS topic defined above, so that whenever the topic
3232 # receives a message, the Lambda function is invoked
3333 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):
2020 payload = json .load (f )
2121
2222 # (2) Act: call the actual lambda with a valid SNS message
23- result = await product .handler (payload )
23+ result = await product .handler (payload , {} )
2424
2525 # (3) Assert: should return
2626 assert result == num_products + 1
You can’t perform that action at this time.
0 commit comments