php-awsHow can I use AWS PHP SDK without credentials?
The AWS PHP SDK can be used without credentials by using the AnonymousAWSCredentials
class. This can be used to make basic requests to AWS services without the need for any credentials.
Below is an example of how to use the AnonymousAWSCredentials
class to make a request to the AWS S3 service:
// Include the AWS SDK
require 'vendor/autoload.php';
// Create a new anonymous credentials object
$credentials = new Aws\Credentials\AnonymousAWSCredentials();
// Create a new S3 client using the anonymous credentials
$s3Client = new Aws\S3\S3Client([
'region' => 'us-east-1',
'version' => 'latest',
'credentials' => $credentials
]);
// Make a request to the S3 service
$result = $s3Client->listBuckets();
// Output the result
print_r($result);
Output example
Array
(
[Buckets] => Array
(
[0] => Array
(
[Name] => my-bucket
[CreationDate] => 2020-10-20T12:34:56+00:00
)
...
)
)
The code above consists of the following parts:
- Include the AWS SDK:
require 'vendor/autoload.php';
- Create a new anonymous credentials object:
$credentials = new Aws\Credentials\AnonymousAWSCredentials();
- Create a new S3 client using the anonymous credentials:
$s3Client = new Aws\S3\S3Client([
'region' => 'us-east-1',
'version' => 'latest',
'credentials' => $credentials
]);
- Make a request to the S3 service:
$result = $s3Client->listBuckets();
- Output the result:
print_r($result);
For more information, please refer to the AWS PHP SDK Documentation.
More of Php Aws
- 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 PHP to create an asynchronous application on AWS?
- How can I use AWS WAF to secure my PHP application?
- 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...