aws-samples / aws-samples/aws-serverless-developer-experience-workshop-python

Cross-runtime consistency fixes

未關閉
#178 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
pending-release
主要語言
Python
星號
47
分支
20
PR 合併指標
30 天內沒有已合併 PR

描述

## Summary

A set of fixes to align the Python runtime with the other runtimes (Java, TypeScript, .NET) for functional equivalence and cross-runtime consistency.

---

## Contracts Service

### Timestamp format (`contract_event_handler.py`)
- `create_contract`: replaced `datetime.now().strftime("%d/%m/%Y %H:%M:%S")` with `datetime.now(timezone.utc).isoformat()` for both `contract_created` and `contract_last_modified_on`
- `update_contract`: replaced `datetime.now().strftime(...)` with `datetime.now(timezone.utc).isoformat()`
- Format change: custom `DD/MM/YYYY HH:MM:SS` → ISO 8601 `YYYY-MM-DDTHH:MM:SS.ffffff+00:00`
- Uses the non-deprecated timezone-aware API (`timezone.utc`) instead of `datetime.utcnow()`

### DynamoDB attribute name (`contract_event_handler.py`)
- `update_contract`: changed `UpdateExpression` from `"set contract_status=:t, modified_date=:m"` to `"set contract_status=:t, contract_last_modified_on=:m"`
- This corrects a bug where `update_contract` wrote to a non-existent `modified_date` attribute instead of the correct `contract_last_modified_on` attribute used in `create_contract`

### Observability metrics (`contract_event_handler.py`)
- Added `metrics.add_metric(name="ContractCreated", unit=MetricUnit.Count, value=1)` to `create_contract` success path

---

## Approvals Service

### Per-invocation timestamp (`contract_status_changed_event_handler.py`)
- Removed module-level `now = datetime.now()` and `current_date` variable assignments
- Moved timestamp computation inside the handler function body to ensure each invocation captures its own execution time rather than the container initialisation time

### Environment variable error type (`contract_status_changed_event_handler.py`)
- Replaced `raise InternalServerError(...)` with `raise EnvironmentError(...)` for both `SERVICE_NAMESPACE` and `CONTRACT_STATUS_TABLE` missing variable checks
- Removed the now-unused `InternalServerError` import from `aws_lambda_powertools.event_handler.exceptions`

---

## Web Service

### Evaluation result validation (`publication_evaluation_event_handler.py`)
- Added validation guard: only updates DynamoDB when `evaluation_result` is `"APPROVED"` or `"DECLINED"` (case-insensitive)
- Logs a warning and returns without writing to DynamoDB for any other value

### Metric name correction (`publication_evaluation_event_handler.py`)
- Removed duplicate `metrics.add_metric(name="PropertiesAdded", ...)` call
- Retained `metrics.add_metric(name="PropertiesApproved", ...)` as the single metric for this path

貢獻指南

開啟貢獻指南

研究方向

將 contract_event_handler.py、contract_status_changed_event_handler.py 和 publication_evaluation_event_handler.py 與 Java、TypeScript 和 .NET runtime 進行比較。先檢查所列出的時間戳、DynamoDB、環境變數、驗證和指標行為,然後在可用時執行相關的服務測試。當 Python 處理程式符合所述的跨 runtime 合約,且沒有非預期寫入或重複指標時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
aws, python
領域
backend, cloud
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。