SDK for PHP에서 자격 증명 메모이제이션 - AWS SDK for PHP

SDK for PHP에서 자격 증명 메모이제이션

때로는 이전 반환 값을 기억하는 보안 인증 공급자를 생성해야 할 수도 있습니다. 이 공급자는 보안 인증 로딩이 비용이 많이 드는 작업인 경우 또는 Aws\Sdk 클래스를 사용하여 여러 클라이언트 간에 보안 인증 공급자를 공유하는 경우 성능에 유용합니다. 보안 인증 공급자 함수를 memoize 함수 안에 래핑하여 메모이제이션(memoization)을 보안 인증 공급자에 추가할 수 있습니다.

use Aws\Credentials\CredentialProvider; $provider = CredentialProvider::instanceProfile(); // Wrap the actual provider in a memoize function $provider = CredentialProvider::memoize($provider); // Pass the provider into the Sdk class and share the provider // across multiple clients. Each time a new client is constructed, // it will use the previously returned credentials as long as // they haven't yet expired. $sdk = new Aws\Sdk(['credentials' => $provider]); $s3 = $sdk->getS3(['region' => 'us-west-2', 'version' => 'latest']); $ec2 = $sdk->getEc2(['region' => 'us-west-2', 'version' => 'latest']); assert($s3->getCredentials() === $ec2->getCredentials());

메모이제이션(memoization)된 보안 인증이 만료되면 메모이제이션 래퍼가 보안 인증을 새로 고치려고 시도할 때 래핑된 공급자를 호출합니다.