Can't pass my credentials to AWS PHP SDK

前端 未结 3 1778
梦如初夏
梦如初夏 2021-01-07 06:55

I installed AWS PHP SDK and am trying to use SES. My problem is that it\'s (apparently) trying to read ~/.aws/credentials no matter what I do. I currently have

相关标签:
3条回答
  • 2021-01-07 07:25

    This solution will probably only work if you're using version 3 of the SDK. I use something similar to this:

    $provider = CredentialsProvider::memoize(CredentialsProvider::ini($profile, $path));
    $client = new SesClient([
        'version' => 'latest',
        'region'  => 'us-east-1',
        'credentials' => $provider]);
    

    I use this for S3Client, DynamoDbClient, and a few other clients, so I am assuming that the SesClient constructor supports the same arguments.

    0 讨论(0)
  • 2021-01-07 07:26

    OK, I managed to fix it. I couldn't read the credentials file but it wasn't exactly my idea. What was happening was that the actual client was being created successfully, but the try/catch also had the sendEmail included. This was what was failing. About creating the client with explicit credentials: If you specify region, it will try and read a credentials file.

    About the SendEmail, this is the syntax that worked for me, I'd found another one also in the AWS docs site, and that one failed. It must've been for an older SDK.

    0 讨论(0)
  • 2021-01-07 07:28

    The trick is just remove 'profile' => 'default' from the factory params, if this is defined we can't use a custom credentials file or environment variables. Is not documented but just works.

    I'm using Sns and Sdk v3.

    <?php
    use Aws\Credentials\CredentialProvider;
    
    $profile = 'sns-reminders';
    $path = '../private/credentials';
    
    $provider = CredentialProvider::ini($profile, $path);
    $provider = CredentialProvider::memoize($provider);
    
    $sdk = new Aws\Sdk(['credentials' => $provider]);
    
    $sns = $sdk->createSns([
    //        'profile' => $profile,
            'region'  => 'us-east-1',
            'version' => 'latest',
    ]);
    
    0 讨论(0)
提交回复
热议问题