/** * If {@link #isAutomaticRefreshEnabled()} and {@link #isNearExpiration()} * fetch the latest IAM role credentials from EC2 instance data and * re-populate this object (via {@link #refreshFromEC2InstanceData()}. */ public synchronized void refreshFromEC2InstanceDataIfNearExpiration() { if (this.automaticRefreshEnabled && this.isNearExpiration()) { // Only attempt refresh at sensible intervals, to avoid hammering // the instance metadata service if it is temporarily unvailable long msSinceLastRetry = System.currentTimeMillis() - this.automaticRefreshLastRetryMS; if (msSinceLastRetry / 1000 < this.automaticRefreshRetryDelaySeconds) { return; // Skip too-soon refresh attempts } try { this.automaticRefreshLastRetryMS = System.currentTimeMillis(); this.refreshFromEC2InstanceData(); } catch (Exception ex) { log.warn("Failed to automatically refresh IAM role credentials" + " from EC2 instance data", ex); } } }
/** * If {@link #isAutomaticRefreshEnabled()} and {@link #isNearExpiration()} * fetch the latest IAM role credentials from EC2 instance data and * re-populate this object (via {@link #refreshFromEC2InstanceData()}. */ public synchronized void refreshFromEC2InstanceDataIfNearExpiration() { if (this.automaticRefreshEnabled && this.isNearExpiration()) { // Only attempt refresh at sensible intervals, to avoid hammering // the instance metadata service if it is temporarily unvailable long msSinceLastRetry = System.currentTimeMillis() - this.automaticRefreshLastRetryMS; if (msSinceLastRetry / 1000 < this.automaticRefreshRetryDelaySeconds) { return; // Skip too-soon refresh attempts } try { this.automaticRefreshLastRetryMS = System.currentTimeMillis(); this.refreshFromEC2InstanceData(); } catch (Exception ex) { log.warn("Failed to automatically refresh IAM role credentials" + " from EC2 instance data", ex); } } }