Skip to content

Make alert_before_expiry configurable - #101

Merged
onno-vos-dev merged 1 commit into
aws-beam:masterfrom
ethunk:feature/allow-alert-before-expiry-to-be-configurable
Aug 5, 2026
Merged

Make alert_before_expiry configurable#101
onno-vos-dev merged 1 commit into
aws-beam:masterfrom
ethunk:feature/allow-alert-before-expiry-to-be-configurable

Conversation

@ethunk

@ethunk ethunk commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Problem

The library refreshes credentials 5 minutes before expiry, and that window is hardcoded (?ALERT_BEFORE_EXPIRY, 300).

I'm using this library to retrieve a token used for a long-running file transfer. The transfer can take longer than 5 minutes, so the token can expire mid-transfer. Rather than forcing a fresh token fetch before every transfer job, I'd like to be able to widen the refresh window so I can guarantee no token is ever within X minutes of expiring — enough to cover the transfer's duration.

Change

Exposes the refresh window via the alert_before_expiry application environment variable (in seconds), defaulting to the existing 300 (5 minutes) if unset:

{aws_credentials, [{alert_before_expiry, 600}]}.

Testing

  • Added a CT test (config group in aws_credentials_SUITE) that sets alert_before_expiry to 60, mocks the EC2 provider with a known expiry, and asserts the scheduled refresh timer fires at expiry - 60s.
  • Fixed a latent test leak found while adding this: the generic end_per_testcase never unloaded the aws_credentials_file meck, which corrupted aws_credentials_providers_SUITE when run in the same VM as the new test.
  • rebar3 compile, lint, eunit, ct, dialyzer, and xref all pass.
  • Updated README to document the new variable.

The 5-minute refresh buffer before token expiration was hardcoded,
forcing callers with long-running operations (e.g. a file transfer
exceeding 5 minutes) to force a fresh credential fetch beforehand
rather than relying on the automatic background refresh.

Expose it via the alert_before_expiry application environment
variable so callers can widen the buffer to cover their own
operation's duration.
@onno-vos-dev

Copy link
Copy Markdown
Member

Hi there, sounds reasonable to me! I'll review tonight and roll out a release of it looks good 👍

Starting the pipeline at least now so you get feedback in case it fails 👍

@onno-vos-dev
onno-vos-dev merged commit b788a4d into aws-beam:master Aug 5, 2026
6 checks passed
@onno-vos-dev

Copy link
Copy Markdown
Member

@ethunk Tagged and released as 1.1.1: https://hex.pm/packages/aws_credentials/1.1.1

Thank you for your contribution 🙇

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.

2 participants