@@ -31,6 +31,8 @@ class LambdaContext:
3131 def __init__(self, function_name: str):
3232 self.function_name = function_name
3333 self.invoked_function_arn = f"arn:aws:lambda:us-east-1:account-id:function:{self.function_name}"
34+ self.aws_request_id = "52fdfc07-2182-154f-163f-5f0f9a621d72"
35+ self.log_stream_name = "2024/03/01/[$LATEST]abcdef0123456789"
3436
3537
3638class TestAWSLambda:
@@ -67,6 +69,38 @@ def build_headers(self, timestamp: str, body: str):
6769 "x-slack-request-timestamp": [timestamp],
6870 }
6971
72+ def test_lambda_context_in_bolt_context(self):
73+ app = App(client=self.web_client, signing_secret=self.signing_secret)
74+ captured = {}
75+
76+ @app.middleware
77+ def capture(context, next):
78+ captured.update(context)
79+ next()
80+
81+ app.event("app_mention")(lambda: None)
82+ input = {
83+ "token": "verification_token",
84+ "team_id": "T111",
85+ "api_app_id": "A111",
86+ "event": {"type": "app_mention", "text": "hi", "user": "W222", "team": "T111", "channel": "C111"},
87+ "type": "event_callback",
88+ "event_id": "Ev111",
89+ "event_time": 1595926230,
90+ }
91+ timestamp, body = str(int(time())), json.dumps(input)
92+ event = {
93+ "body": body,
94+ "queryStringParameters": {},
95+ "headers": self.build_headers(timestamp, body),
96+ "requestContext": {"http": {"method": "POST"}},
97+ "isBase64Encoded": False,
98+ }
99+ response = SlackRequestHandler(app).handle(event, self.context)
100+ assert response["statusCode"] == 200
101+ assert captured["aws_lambda_request_id"] == self.context.aws_request_id
102+ assert captured["aws_lambda_log_stream_name"] == self.context.log_stream_name
103+
70104 def test_not_found(self):
71105 response = not_found()
72106 assert response["statusCode"] == 404
0 commit comments