Skip to content

[v2] Port/Update usage of datetime.utcnow for DeprecationWarnings#10488

Closed
kdaily wants to merge 5 commits into
v2from
kdaily-utcnow-deprecation-fix
Closed

[v2] Port/Update usage of datetime.utcnow for DeprecationWarnings#10488
kdaily wants to merge 5 commits into
v2from
kdaily-utcnow-deprecation-fix

Conversation

@kdaily

@kdaily kdaily commented Jul 15, 2026

Copy link
Copy Markdown
Member

Issue #, if available:

N/A - Port of upstream botocore fixes for Python 3.12+ compatibility.

Description of changes:

Python 3.12 deprecated datetime.datetime.utcnow(). This PR ports the upstream botocore fix and applies the same pattern to awscli customization modules.

From PR boto/botocore#3239:

  • Port b0015b7: Replace datetime.datetime.utcnow()withdatetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)in botocore auth/signing code. Update test mocks from.utcnowto.now`.

From boto/botocore#3533:

  • Port 7ebb8b8: Introduce get_current_datetime() utility in botocore.compat to centralize the pattern. CRT auth uses get_current_datetime(remove_tzinfo=False) since CRT expects timezone-aware datetimes.
  • Port bbed2c0: Add tzinfo=datetime.timezone.utc to test datetime fixtures to match production behavior.

Additionally:

  • Fix s3 presign test: Update mock from .utcnow to .now in test_presign_command.py.
  • Fix awscli customization modules: Replace datetime.utcnow() in eks/get_token.py, logs/tail.py, and ec2/bundleinstance.py. Update test mocks across 7 functional test files.

Upstream references:

kdaily added 5 commits July 15, 2026 12:12
Port of botocore commit b0015b7 (PR #3239) by @kurtmckee.

Replace datetime.datetime.utcnow() with
datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None) to
resolve the Python 3.12 DeprecationWarning while ensuring datetime
instances remain timezone-unaware for backward compatibility.

Update test mocks from .utcnow to .now to match the new code paths.

Upstream: boto/botocore@b0015b7
Upstream PR: boto/botocore#3239
Port of botocore commit 7ebb8b8 (PR #3533) by @nateprewitt.

Introduce get_current_datetime() utility in botocore.compat to
centralize the datetime.now(timezone.utc) pattern. This makes it
easier to mock in tests and provides a single point of maintenance
for timezone-aware datetime retrieval.

The CRT auth module uses get_current_datetime(remove_tzinfo=False)
since the CRT library expects timezone-aware datetime objects.

Upstream: boto/botocore@7ebb8b8
Upstream PR: boto/botocore#3533
Port of botocore commit bbed2c0 (PR #3533) by @nateprewitt.

Add tzinfo=datetime.timezone.utc to test datetime fixtures to match
the real behavior of get_current_datetime() which internally calls
datetime.datetime.now(datetime.timezone.utc). This ensures mocked
return values are consistent with production code behavior, which is
important for the CRT auth path that uses remove_tzinfo=False.

Upstream: boto/botocore@bbed2c0
Upstream PR: boto/botocore#3533
Follow-up to the botocore utcnow deprecation port. The presign command
test was still mocking datetime.datetime.utcnow instead of .now, causing
6 test failures.

Upstream: boto/botocore@b0015b7
Upstream PR: boto/botocore#3239
Replace datetime.utcnow() with datetime.now(timezone.utc) in awscli
customization modules that were not covered by the botocore port:

- awscli/customizations/eks/get_token.py
- awscli/customizations/logs/tail.py (via _utcnow helper)
- awscli/customizations/ec2/bundleinstance.py

Update test mocks from .utcnow to .now across all affected test files:

- tests/functional/botocore/test_s3express.py
- tests/functional/eks/test_get_token.py
- tests/functional/logs/test_tail.py
- tests/functional/dsql/test_generate_db_auth_token.py
- tests/functional/rds/test_generate_db_auth_token.py
- tests/functional/ec2instanceconnect/test_opentunnel.py
- tests/functional/ec2/test_bundle_instance.py
@kdaily kdaily closed this Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant