Skip to content

Commit c48c6b0

Browse files
committed
Add a code example of integrating with the AWS SDK for PHP [skip ci]
1 parent 8c4b206 commit c48c6b0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,37 @@ $ aws lambda update-function-configuration \
141141
--layers "arn:aws:lambda:us-east-1:XXXXXXXXXXXX:layer:lambda-xp-runtime:2"
142142
```
143143

144+
Using other AWS services
145+
------------------------
146+
In order to programmatically use other AWS services such as SQS with the [AWS SDK for PHP](https://docs.aws.amazon.com/sdk-for-php/index.html), pass the credentials via environment:
147+
148+
```php
149+
use Aws\Sqs\SqsClient;
150+
use Aws\Credentials\CredentialProvider;
151+
use com\amazon\aws\lambda\Handler;
152+
153+
class Trigger extends Handler {
154+
155+
/** @return com.amazon.aws.lambda.Lambda|callable */
156+
public function target() {
157+
$queue= new SqsClient([
158+
'version' => '2012-11-05',
159+
'region' => $this->environment->variable('AWS_REGION'),
160+
'credentials' => CredentialProvider::env(),
161+
]);
162+
163+
// ...omitted for brevity...
164+
}
165+
}
166+
```
167+
168+
To test this locally, pass the necessary environment variables via *-e* on the command line:
169+
170+
```bash
171+
$ xp lambda test -e AWS_ACCESS_KEY_ID=... -e AWS_SECRET_ACCESS_KEY=... Trigger
172+
# ...
173+
```
174+
144175
Context
145176
-------
146177
The context object passed to the target lambda is defined as follows:

0 commit comments

Comments
 (0)