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 can I use AWS and Zksync together with PHP?
- How can I use an AWS SQS Worker with PHP?
- How can I use AWS WAF to secure my PHP application?
- How do I generate an AWS Signature Version 4 with PHP?
- How can I use the AWS S3 S3Client library with PHP?
- How can I use AWS Textract with PHP?
- How can I connect to Amazon Web Services (AWS) S3 using PHP?
- How can I use PHP and AWS Transcribe to transcribe audio files?
- How can I use the PHP AWS SDK to send messages via SNS?
- How can I use the PHP AWS S3 S3Client to upload files?
See more codes...