|
1 | 1 | """Integration tests for CloudWatchProvider against real CloudWatch Logs data. |
2 | 2 |
|
3 | | -Requires AWS credentials with CloudWatch Logs read access. Uses the |
4 | | -'strands_github_bot' AWS profile if available, otherwise falls back to default credentials. |
| 3 | +Requires the following environment variables: |
| 4 | + CLOUDWATCH_TEST_LOG_GROUP — CW Logs group containing agent traces |
| 5 | + CLOUDWATCH_TEST_SESSION_ID — session ID with convertible spans |
| 6 | + AWS_REGION (optional) — defaults to us-east-1 |
| 7 | +
|
| 8 | +AWS credentials must be configured via standard mechanisms (env vars, profile, instance role). |
| 9 | +
|
5 | 10 | Run with: pytest tests_integ/test_cloudwatch_provider.py -v |
6 | 11 | """ |
7 | 12 |
|
8 | | -import boto3 |
| 13 | +import os |
| 14 | + |
9 | 15 | import pytest |
10 | 16 |
|
11 | 17 | from strands_evals import Case, Experiment |
|
27 | 33 | Trace, |
28 | 34 | ) |
29 | 35 |
|
30 | | -LOG_GROUP = "/aws/bedrock-agentcore/runtimes/github_issue_handler-zf6fZR2saQ-DEFAULT" |
31 | | - |
32 | | -KNOWN_SESSION_IDS = [ |
33 | | - "github_issue_68_20260218_172558_d27beb07", |
34 | | - "github-issue-68-1771435544179-d5gc8kk4xan", |
35 | | -] |
36 | | - |
37 | | -EXPECTED_ACCOUNT_ID = "249746592913" |
38 | | -AWS_PROFILE = "strands_github_bot" |
39 | | -AWS_REGION = "us-east-1" |
40 | | - |
41 | | - |
42 | | -def _create_logs_client() -> boto3.client | None: |
43 | | - """Try the named profile first, then fall back to default credentials.""" |
44 | | - for profile in [AWS_PROFILE, None]: |
45 | | - try: |
46 | | - session = boto3.Session(profile_name=profile, region_name=AWS_REGION) |
47 | | - sts = session.client("sts") |
48 | | - identity = sts.get_caller_identity() |
49 | | - if identity["Account"] == EXPECTED_ACCOUNT_ID: |
50 | | - return session.client("logs") |
51 | | - except Exception: |
52 | | - continue |
53 | | - return None |
54 | | - |
55 | 36 |
|
56 | 37 | @pytest.fixture(scope="module") |
57 | 38 | def provider(): |
58 | | - """Create a CloudWatchProvider targeting the correct AWS account.""" |
59 | | - client = _create_logs_client() |
60 | | - if client is None: |
61 | | - pytest.skip(f"No AWS credentials found for account {EXPECTED_ACCOUNT_ID}") |
| 39 | + """Create a CloudWatchProvider using env var configuration.""" |
| 40 | + log_group = os.environ.get("CLOUDWATCH_TEST_LOG_GROUP") |
| 41 | + if not log_group: |
| 42 | + pytest.skip("CLOUDWATCH_TEST_LOG_GROUP not set") |
| 43 | + |
| 44 | + region = os.environ.get("AWS_REGION", "us-east-1") |
62 | 45 |
|
63 | 46 | try: |
64 | | - cw = CloudWatchProvider(log_group=LOG_GROUP, region=AWS_REGION) |
| 47 | + return CloudWatchProvider(log_group=log_group, region=region) |
65 | 48 | except ProviderError as e: |
66 | 49 | pytest.skip(f"CloudWatch provider creation failed: {e}") |
67 | 50 |
|
68 | | - # Inject the verified client |
69 | | - cw._client = client |
70 | | - return cw |
71 | | - |
72 | 51 |
|
73 | 52 | @pytest.fixture(scope="module") |
74 | | -def session_id(provider): |
75 | | - """Try known session IDs; skip if none found.""" |
76 | | - for sid in KNOWN_SESSION_IDS: |
77 | | - try: |
78 | | - provider.get_evaluation_data(sid) |
79 | | - return sid |
80 | | - except (SessionNotFoundError, ProviderError): |
81 | | - continue |
82 | | - pytest.skip("No known sessions found in CloudWatch") |
| 53 | +def session_id(): |
| 54 | + """Get a test session ID from environment variable.""" |
| 55 | + sid = os.environ.get("CLOUDWATCH_TEST_SESSION_ID") |
| 56 | + if not sid: |
| 57 | + pytest.skip("CLOUDWATCH_TEST_SESSION_ID not set") |
| 58 | + return sid |
83 | 59 |
|
84 | 60 |
|
85 | 61 | @pytest.fixture(scope="module") |
|
0 commit comments