I am using Centos 7 inside docker, with the environment 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).
inside my docker container, there is one file php file there I have write the code to check is aws cli is accessible or not.
When I attempt to access the browser, it displays an error message: ‘Error loading SSO Token: The SSO access token has either expired or is otherwise invalid.’ However, when I run the same file inside the container, it functions as expected. It should behave the same way in the browser as well."
FYI: This is my code.
<?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>";
2
Answers
After lots of effort, I finally found the solution. It was a permission issue. I just granted 777 permission to the
root
folder. Now, how do I debug this code? I used the--debug
flag at the end of the AWS command like this:exec("$env /usr/bin/aws secretsmanager get-random-password --debug 2>&1 ", $output, $return);
I want to express my gratitude to Avinash Dalvi for helping me fix this code. They actually gave me the idea to use the --debug flag and read the error.
Debug issue:
After fix :
I also faced the same issue. To resolve this issue, I had to logout from AWS SSO first and then login again through CLI.