【发布时间】:2021-09-22 21:49:03
【问题描述】:
我的 EC2 实例连接到我们的 S3 存储桶时遇到问题。
在我的 ec2 实例上,我安装了 php、httpd、aws-cli、aws-sdk。我能够访问代码所在的索引页面。凭据文件设置 /usr/share/httpd/.aws/credentials
我使用的代码来自Getting Started Basic Usage Guide
$sharedConfig = [
'profile' => 'default',
'region' => 'us-west-1',
'version' => 'latest',
'debug' => true
];
// Create an SDK class used to share configuration across clients.
$sdk = new Aws\Sdk($sharedConfig);
// Use an Aws\Sdk class to create the S3Client object.
$s3Client = $sdk->createS3();
// Send a PutObject request and get the result object.
$result = $s3Client->putObject([
'Bucket' => 'my-bucket',
'Key' => 'my-key',
'Body' => 'this is the body!'
]);
使用调试模式会导致大量文本转储。我认为主要错误属于 s3 存储桶拒绝来自代码的连接。
Entering step attempt, name 'ApiCallAttemptMonitoringMiddleware' ------
no changes * Trying IP_ADDRESS... * TCP_NODELAY set * Immediate connect fail for IP_ADDRESS: Permission denied *
Closing connection 0 <- Leaving step attempt, name 'ApiCallAttemptMonitoringMiddleware' --------- error was set to array(13) { ["instance"]=> string(32) "0000000078dd756a0000000053d619cb" ["class"]=> string(28) "Aws\S3\Exception\S3Exception" ["message"]=> string(241) "Error executing "PutObject" on "https://ec2-server-test.s3.us-west-1.amazonaws.com/my-key";
AWS HTTP error: cURL error 7: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://ec2-server-test.s3.us-west-1.amazonaws.com/my-key" ["file"]=> string(58) "/var/www/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php" ["line"]=> int(195) ["trace"]=> string(1925) "#0 /var/www/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php(100)
Curl 错误 7:无法 connect() 到主机或代理。
通过 SSH 连接到我的实例时,我能够正确运行 aws-cli s3 命令并收到正确的响应。
此代码也可以在我通过 xampp 托管的机器上本地运行。
【问题讨论】:
标签: amazon-web-services amazon-s3 amazon-ec2 aws-cli aws-php-sdk