php-awsHow can I access the result object from an AWS API call using PHP?
Using the AWS SDK for PHP, you can access the result object from an AWS API call. The following example code will demonstrate this:
<?php
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';
// Instantiate an Amazon S3 client.
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => [
'key' => 'YOUR_AWS_ACCESS_KEY_ID',
'secret' => 'YOUR_AWS_SECRET_ACCESS_KEY',
]
]);
// Call the Amazon S3 API
$result = $s3->listBuckets();
// Access the result object
echo $result['Buckets'][0]['Name'];
// Outputs: example-bucket
The code above:
- Includes the SDK using the Composer autoloader.
- Instantiates an Amazon S3 client.
- Calls the Amazon S3 API.
- Accesses the result object and prints the name of the first bucket.
The output of the code is:
example-bucket
For more information, see the AWS SDK for PHP documentation.
More of Php Aws
- How can I use PHP to connect to an Amazon Aurora database?
- How do I use PHP to create a ZIP file on AWS?
- How can I use AWS and Zksync together with PHP?
- How can I use Yum to install PHP on an Amazon EC2 instance?
- How can I use an AWS SQS Worker with PHP?
- How can I use AWS WAF to secure my PHP application?
- How can I use AWS PHP SDK without credentials?
- How do I generate an AWS Signature Version 4 with PHP?
- How do I determine the version of PHP I am running on AWS?
- How can I use the AWS S3 S3Client library with PHP?
See more codes...