aws/aws-sdk-php
AWS SDK for PHP (v3) provides a full-featured client library for calling Amazon Web Services from PHP 8.1+, including S3, DynamoDB, Glacier, and more. Install via Composer (aws/aws-sdk-php) and authenticate with AWS credentials.
## Getting Started
### Minimal Setup in Laravel
1. **Installation**
```bash
composer require aws/aws-sdk-php
For Laravel-specific integration (recommended):
composer require aws/aws-sdk-php-laravel
Configuration
Add AWS credentials to .env:
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_DEFAULT_REGION=us-east-1
First Use Case: S3 File Upload (Unchanged)
use Aws\S3\S3Client;
$s3 = app(S3Client::class); // Laravel service provider injects config
$result = $s3->putObject([
'Bucket' => 'your-bucket',
'Key' => 'file.txt',
'Body' => fopen('local-file.txt', 'r'),
'ACL' => 'public-read'
]);
New Use Case: MediaLive with MediaConnect Router
use Aws\MediaLive\MediaLiveClient;
$mediaLive = app(MediaLiveClient::class);
$result = $mediaLive->createChannel([
'Name' => 'MyChannel',
'Inputs' => [
[
'Name' => 'Input1',
'Type' => 'SDI',
'Destinations' => [
[
'StreamName' => 'Output1',
'Type' => 'MEDIACONNECT_ROUTER', // New output type
'Settings' => [
'RouterName' => 'MyRouter',
'RouterInterfaceName' => 'Interface1'
]
]
]
]
]
]);
Key Files to Reference
config/aws.php (auto-generated by Laravel package)vendor/aws/aws-sdk-php/src/ (core SDK)vendor/aws/aws-sdk-php-laravel/src/ (Laravel bindings)vendor/aws/aws-sdk-php/src/Aws/MediaLive/ for MediaConnect Routervendor/aws/aws-sdk-php/src/Aws/MarketplaceDiscovery/ for catalog operationsPattern: Use Laravel's service container for dependency injection
// In service provider
$this->app->singleton(MediaLiveClient::class, function ($app) {
return new MediaLiveClient([
'version' => 'latest',
'region' => config('aws.region'),
'credentials' => [
'key' => config('aws.key'),
'secret' => config('aws.secret'),
]
]);
});
MediaLive with MediaConnect Router:
// Create a channel with MediaConnect Router output
$mediaLive = app(MediaLiveClient::class);
$channel = $mediaLive->createChannel([
'Name' => 'LiveStreamChannel',
'Inputs' => [
[
'Name' => 'Input1',
'Destinations' => [
[
'StreamName' => 'RouterOutput',
'Type' => 'MEDIACONNECT_ROUTER',
'Settings' => [
'RouterName' => 'MyMediaConnectRouter',
'RouterInterfaceName' => 'PrimaryInterface'
]
]
]
]
]
]);
Marketplace Discovery (New):
// Search for products in AWS Marketplace
$marketplace = app(Aws\MarketplaceDiscovery\MarketplaceDiscoveryClient::class);
$search = $marketplace->searchProducts([
'Filters' => [
'ProductType' => ['Software'],
'Categories' => ['DevOps']
],
'MaxResults' => 10
]);
Backup for EKS (New):
// Create a backup vault with EKS notification
$backup = app(Aws\Backup\BackupClient::class);
$vault = $backup->createBackupVault([
'BackupVaultName' => 'eks-vault',
'Notifications' => [
'BackupJobFailedNotification' => 'arn:aws:sns:us-east-1:123456789012:EKSBackupTopic',
'BackupJobCompletedNotification' => 'arn:aws:sns:us-east-1:123456789012:EKSBackupTopic',
'CopyJobFailedNotification' => 'arn:aws:sns:us-east-1:123456789012:EKSBackupTopic',
'CopyJobCompletedNotification' => 'arn:aws:sns:us-east-1:123456789012:EKSBackupTopic',
'RestoreJobFailedNotification' => 'arn:aws:sns:us-east-1:123456789012:EKSBackupTopic',
'RestoreJobCompletedNotification' => 'arn:aws:sns:us-east-1:123456789012:EKSBackupTopic',
'NotificationType' => 'EKS_SPECIFIC' // New EKS-specific type
]
]);
$iterator = $s3->getPaginator('ListObjects', [
'Bucket' => 'bucket'
]);
foreach ($iterator as $page) {
foreach ($page['Contents'] as $object) {
// Process each object
}
}
try {
$ecr = app(Aws\ECR\ECRClient::class);
$referrers = $ecr->listImageReferrers([
'repositoryName' => 'my-repo',
'imageId' => ['imageTag' => 'latest']
]);
} catch (Aws\ECR\Exception\UnableToListUpstreamImageReferrersException $e) {
Log::error('ECR Referrers Error: ' . $e->getMessage());
// Handle specific ECR exception
}
// Override config per environment
config([
'aws.region' => 'eu-west-1',
'aws.version' => '2012-10-17'
]);
// Per-client configuration for new services
$mediaLive = new Aws\MediaLive\MediaLiveClient([
'region' => 'us-west-2',
'version' => '2017-10-26' // MediaLive API version
]);
Credentials Caching (Unchanged)
Aws\Common\Credentials\Credentials::clearStaticCache();
Region Mismatches (Unchanged)
$marketplace = new Aws\MarketplaceDiscovery\MarketplaceDiscoveryClient([
'region' => 'us-east-1' // Marketplace Discovery is region-specific
]);
New Service-Specific Quirks
RouterName and RouterInterfaceName for outputs.NextToken for subsequent pages).GetProductById).NotificationType set to EKS_SPECIFIC for EKS-related events.Large File Uploads (Unchanged)
IAM Permissions (Updated)
mediaconnect:CreateRouter, mediaconnect:DescribeRoutermarketplacediscovery:SearchProducts, marketplacediscovery:GetProductByIdbackup:CreateBackupVault, backup:PutBackupVaultNotificationsEnable Wire Logging (Unchanged)
$client = new MediaLiveClient([
'region' => 'us-west-2',
'debug' => true,
'logger' => new Aws\Common\Logger\LogLevelLogger(
new Aws\Common\Logger\StreamLogger('php://stdout'),
Aws\Common\Logger\LogLevel::DEBUG
)
]);
New Service-Specific Debugging
$mediaconnect = app(Aws\MediaConnect\MediaConnectClient::class);
$router = $mediaconnect->describeRouter(['Name' => '
How can I help you explore Laravel packages today?