0

I am trying to convert aws to upload with wasabi api and it says it runs with aws so I am looking to put in my access key after instantiation but cant find the file in which the keys go into. On the other hand, If you know how to integrate wasabi s3 api into my website that would be a great help for me to know thank you.

aws/credientials/credientials.php

<?php
namespace Aws\Credentials;

/**
 * Basic implementation of the AWS Credentials interface that allows callers to
 * pass in the AWS Access Key and AWS Secret Access Key in the constructor.
 */
class Credentials implements CredentialsInterface, \Serializable
{
    private $key;
    private $secret;
    private $token;
    private $expires;

    /**
     * Constructs a new BasicAWSCredentials object, with the specified AWS
     * access key and AWS secret key
     *
     * @param string $key     AWS access key ID
     * @param string $secret  AWS secret access key
     * @param string $token   Security token to use
     * @param int    $expires UNIX timestamp for when credentials expire
     */
    public function __construct($key, $secret, $token = null, $expires = null)
    {
        $this->key = trim($key);
        $this->secret = trim($secret);
        $this->token = $token;
        $this->expires = $expires;
    }

    public static function __set_state(array $state)
    {
        return new self(
            $state['key'],
            $state['secret'],
            $state['token'],
            $state['expires']
        );
    }

    public function getAccessKeyId()
    {
        return $this->key;
    }

    public function getSecretKey()
    {
        return $this->secret;
    }

    public function getSecurityToken()
    {
        return $this->token;
    }

    public function getExpiration()
    {
        return $this->expires;
    }

    public function isExpired()
    {
        return $this->expires !== null && time() >= $this->expires;
    }

    public function toArray()
    {
        return [
            'key'     => $this->key,
            'secret'  => $this->secret,
            'token'   => $this->token,
            'expires' => $this->expires
        ];
    }

    public function serialize()
    {
        return json_encode($this->toArray());
    }

    public function unserialize($serialized)
    {
        $data = json_decode($serialized, true);

        $this->key = $data['key'];
        $this->secret = $data['secret'];
        $this->token = $data['token'];
        $this->expires = $data['expires'];
    }
}
elisha day
  • 15
  • 1
  • 3

2 Answers2

0

If you are using the AWS Command-Line Interface (CLI) in there somewhere, then the easiest method is to run:

aws configure

It will store the settings in ~/.aws/credentials.

Then, your code does not need to reference the credentials. The SDK will automatically retrieve the credentials from that file.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
0
require('vendor/autoload.php');

use Aws\Ec2\Ec2Client;

$credentials = new Aws\Credentials\Credentials('Your Access Key', 'Your Secret Key'); // Place here both key

$ec2Client = new Aws\Ec2\Ec2Client([
    'version' => 'latest',
    'region'  => 'ap-south-1',
    'credentials' => $credentials
]);

$result = $ec2Client->describeKeyPairs();

echo '<pre>';
print_r($result);

Reference site : https://docs.aws.amazon.com/aws-sdk-php/v2/guide/credentials.html#passing-credentials-into-a-client-factory-method

krunal panchal
  • 417
  • 4
  • 9