Skip to content

Instantly share code, notes, and snippets.

@olcortesb
Created November 13, 2025 16:19
Show Gist options
  • Select an option

  • Save olcortesb/536dbb368d9cd208e12cae7b01f61f3e to your computer and use it in GitHub Desktop.

Select an option

Save olcortesb/536dbb368d9cd208e12cae7b01f61f3e to your computer and use it in GitHub Desktop.
PHP Sample SKD AWS
bash
composer require aws/aws-sdk-php
```
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
$bucketName = $_ENV['S3_BUCKET'] ?? 'your-bucket-name';
$region = $_ENV['AWS_DEFAULT_REGION'] ?? 'us-east-1';
$s3Client = new S3Client([
'version' => 'latest',
'region' => $region
// Las credenciales se toman automáticamente de:
// - Variables de entorno (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
// - IAM Role (si está en EC2/ECS/Lambda)
// - ~/.aws/credentials
]);
try {
$result = $s3Client->listObjectsV2(['Bucket' => $bucketName]);
foreach ($result['Contents'] ?? [] as $object) {
echo $object['Key'] . "\n";
}
} catch (AwsException $e) {
echo "Error: " . $e->getMessage() . "\n";
}
?>
```
```
# Con variables de entorno
export AWS_ACCESS_KEY_ID=your_key
export AWS_SECRET_ACCESS_KEY=your_secret
export S3_BUCKET=your-bucket-name
php s3_ls.php
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment