Closed thekid closed 2 years ago
use com\amazon\aws\lambda\Handler; class Env extends Handler { /** @return com.amazon.aws.lambda.Lambda|callable */ public function target() { return fn($event, $context) => sprintf( 'Hello %s', $this->environment->variable('PROFILE') ?? 'default' ); } }
Invoking the lambda without passing the variable:
$ xp lambda test Env START RequestId: 79bffe4e-226d-147a-c36a-7de3135248e8 Version: $LATEST END RequestId: 79bffe4e-226d-147a-c36a-7de3135248e8 REPORT RequestId: 79bffe4e-226d-147a-c36a-7de3135248e8 Init Duration: 64.10 ms Duration: 4.78 ms... "Hello default"
Passing the environment variable including a value:
$ xp lambda test -e PROFILE=testing Env START RequestId: e51c92b4-e994-13ac-047a-e10ca56eced0 Version: $LATEST END RequestId: e51c92b4-e994-13ac-047a-e10ca56eced0 REPORT RequestId: e51c92b4-e994-13ac-047a-e10ca56eced0 Init Duration: 52.45 ms Duration: 4.01 ms... "Hello testing"
Passing the environment variable:
$ export PROFILE=testing $ xp lambda test -e PROFILE Env START RequestId: dab53651-6c21-1bab-7fa0-f62b7ef488fa Version: $LATEST END RequestId: dab53651-6c21-1bab-7fa0-f62b7ef488fa REPORT RequestId: dab53651-6c21-1bab-7fa0-f62b7ef488fa Init Duration: 54.69 ms Duration: 3.98 ms... "Hello testing"
Released in https://github.com/xp-forge/lambda/releases/tag/v3.2.0
Example
Invoking the lambda without passing the variable:
Passing the environment variable including a value:
Passing the environment variable: