GithubHelp home page GithubHelp logo

Comments (2)

yenfryherrerafeliz avatar yenfryherrerafeliz commented on June 10, 2024

Hi @alaskancode, sorry to hear about your issue. I understand that some improvements could be done here for resolving paths depending on running environment, and this is something I will bring up to the team for discussion. However, there are some alternatives that you can use now for solving this issue and some of them are in the link that you posted already. If you properly set a value for AWS_SHARED_CREDENTIALS_FILE with a location of your preference then, you should have not issues if that location is a valid path and the file is a valid credentials one. I know the docs recommends using setx, but if that did not work then, you may need to check on your environment what is preventing that variable from being set. We can check here that we look at that variable value first and if is set then we give preference to that value over the default one. Windows also has another ways to set environment variables and I encourage you to try them. Below you can see a short example where I set AWS_SHARED_CREDENTIALS_FILE to a custom location and the SDK tried to use that one. Please see below:

<?php
require '../vendor/autoload.php';

use Aws\Credentials\CredentialProvider;
use Aws\S3\S3Client;

putenv("AWS_SHARED_CREDENTIALS_FILE='./mysharedcredsfile'");

$client = new S3Client([
    'region' => 'us-east-2',
    'credentials' => CredentialProvider::ini()
]);
$client->listBuckets();

Here is the output:

PHP Fatal error:  Uncaught Aws\Exception\CredentialsException: Cannot read credentials from './mysharedcredsfile' in $PROJECT_DIR/src/Credentials/CredentialProvider.php:826
Stack trace:
...

Another solution for your issue is to provide the credentials file location explicitly to the credential provider as follow:

<?php
require '../vendor/autoload.php';

use Aws\Credentials\CredentialProvider;
use Aws\S3\S3Client;

$credentialsFilePath = 'YOUR_CUSTOM_CREDENTIALS_FILE_PATH';
$provider = CredentialProvider::ini(null, $credentialsFilePath);
$memoizedProvider = CredentialProvider::memoize($provider);
$s3Client = new S3Client([
    'region' => 'us-east-1',
    'credentials' => $memoizedProvider
]);
$s3Client->listBuckets();

Please let me know if that helps!

Thanks!

from aws-sdk-php.

github-actions avatar github-actions commented on June 10, 2024

This issue has not recieved a response in 1 week. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.

from aws-sdk-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.