我在docker中使用Centos 7,环境为php 8.2、apache、aws cli (aws-cli/2.0.30 Python/3.7.3 Linux/5.15.49-linuxkit-pr botocore/2.0.0dev34)。 在我的 docker 容器内,有一个 php 文件,我编写了代码来检查 aws cli 是否可访问。
当我尝试访问浏览器时,它显示一条错误消息:“加载 SSO 令牌时出错:SSO 访问令牌已过期或无效。”但是,当我在容器内运行相同的文件时,它会按预期运行。它在浏览器中的行为也应该相同。”
仅供参考:这是我的代码。
<?php
if (is_file('/.aws/credentials')) {
echo "AWS Credentials found";
}
$env = 'AWS_DEFAULT_REGION=us-east-2; AWS_DEFAULT_OUTPUT=text AWS_CONFIG_FILE=/.aws/config AWS_SHARED_CREDENTIALS_FILE=/.aws/credentials';
echo "<br>";
echo "CLI S3 Access: ";
exec("$env /usr/bin/aws s3 ls s3://picto-us-east-2-imagery-01/_healthcheck/README.txt 2>&1", $output, $return);
if ($return === 0) {
echo "success";
} else {
echo "failed";
echo "<br>The command failed, check your saml2aws config.<br> Output: <pre>" . print_r($output, true) . "</pre>";
}
echo "<br>";
$output = array();
echo "CLI Secrets Manager: ";
exec("$env /usr/bin/aws secretsmanager get-random-password 2>&1 ", $output, $return);
if ($return === 0) {
echo "success";
} else {
echo "failed";
echo "<br>The command failed, check your saml2aws config.<br> Output: <pre>" . print_r($output, true) . "</pre>";
}
echo "<br>";