credentials = $credentials; $this->client = $client ?: InstanceMetadataClient::factory(); } /** * Attempt to get new credentials from the instance profile * * @throws InstanceProfileCredentialsException On error */ protected function refresh() { $credentials = $this->client->getInstanceProfileCredentials(); // Expire the token 1 minute before it actually expires to pre-fetch before expiring $this->credentials->setAccessKeyId($credentials->getAccessKeyId()) ->setSecretKey($credentials->getSecretKey()) ->setSecurityToken($credentials->getSecurityToken()) ->setExpiration($credentials->getExpiration()); } }