Repository navigation
Expand file tree
/
Copy pathhandler.py
More file actions
51 lines (40 loc) · 1.67 KB
/
Copy pathhandler.py
File metadata and controls
51 lines (40 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
import os
import boto3
from botocore.exceptions import ClientError
dynamodb = boto3.resource("dynamodb")
TEST_RUNS_TABLE = os.environ["TEST_RUNS_TABLE"]
table = dynamodb.Table(TEST_RUNS_TABLE)
def lambda_handler(event, context):
detail = event["detail"]
if not detail.get("inputDetails", {}).get("included", True):
print(f"execution input truncated, cannot recover testId: {detail.get('executionArn')}")
return
try:
execution_input = json.loads(detail.get("input") or "{}")
except json.JSONDecodeError:
print(f"execution input not valid JSON: {detail.get('executionArn')}")
return
test_id = execution_input.get("testId")
if not test_id:
print(f"no testId in execution input: {detail.get('executionArn')}")
return
reason = f"{detail.get('error', '')}: {detail.get('cause', '')}"[:1024]
try:
table.update_item(
Key={"testId": test_id},
UpdateExpression="SET #status = :status, finishedAt = :finishedAt, failureReason = :reason",
ConditionExpression="attribute_exists(testId) AND #status = :running",
ExpressionAttributeNames={"#status": "status"},
ExpressionAttributeValues={
":status": detail.get("status", "FAILED"),
":running": "RUNNING",
":finishedAt": detail.get("stopDate", ""),
":reason": reason,
},
)
except ClientError as exc:
if exc.response["Error"]["Code"] == "ConditionalCheckFailedException":
print(f"test {test_id} not in RUNNING state, skipping (likely duplicate delivery)")
else:
raise