xp-forge / lambda

AWS Lambda for the XP Framework
3 stars 0 forks source link

Make credentials accessible via Environment::credentials() #18

Closed thekid closed 1 year ago

thekid commented 1 year ago

Access to the access keys obtained from the function's execution role, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime

What this pull request simplifies

Before:

$session= $this->environment->variable('AWS_SESSION_TOKEN');
$access= $this->environment->variable('AWS_ACCESS_KEY_ID');
$secret= new Secret($this->environment->variable('AWS_SECRET_ACCESS_KEY'));

After:

$credentials= $this->environment->credentials();

API

public class com.amazon.aws.lambda.Credentials implements lang.Value {
  public function __construct(string $accessKey, string|util.Secret $secretKey, ?string $sessionToken)

  public function accessKey(): string
  public function secretKey(): util.Secret
  public function sessionToken(): ?string
  public function hashCode(): string
  public function toString(): string
  public function compareTo(var $value): int
}
thekid commented 1 year ago

Released in https://github.com/xp-forge/lambda/releases/tag/v4.3.0. However, in the meantime, #19 was merged and the Credentials class is now in the com.amazon.aws base package.