Issue with AWS S3 Access Key Id

0

I am writing to seek assistance with an issue I encountered while attempting to generate a pre-signed URL for accessing an object in an S3 bucket.

Here is the error message I received: <Error> <Code>InvalidAccessKeyId</Code> <Message>The AWS Access Key Id you provided does not exist in our records.</Message> <AWSAccessKeyId>AKIA6K3OIAYRLBDEZTF5SignatureV4.php</AWSAccessKeyId> <RequestId>H9414ADYWA0HENYF</RequestId> <HostId>elc57RtlZvnrh8Jqc171n0nROXJw3nLJj3OzWgByFD2VZnN/VOV04UjBH1qCKFkwBezQYtCBJG0=</HostId> </Error> Here is the relevant PHP code snippet: public function get_object_download_link($bucket_name, $object_key) { // Initialize S3 client $s3Client = $this->initialize_s3_client($credentials['access_key'], $credentials['secret_key'], 'eu-west-2');

try {
    // Generate pre-signed URL
    $command = $s3Client->getCommand('GetObject', [
        'Bucket' => $bucket_name,
        'Key'    => $object_key,
    ]);
    $request = $s3Client->createPresignedRequest($command, '+1 day');
    return (string)$request->getUri();
} catch (AwsException $e) {
    error_log($e->getMessage());
    return 'Error: An error occurred while generating the pre-signed URL.';
}

} The region is set to eu-west-2, and the bucket name is sunfly.mp3. An example object key is SF1127930 - Madison Beer - Make You Mine_Master.mp3.

I would greatly appreciate your assistance in resolving this issue. If you require any additional information or clarification, please do not hesitate to reach out.

Thank you for your attention

1 Answer
0

Hello,

Invalid Access Key ID error message indicates that the AWS Access Key ID provided is not found in AWS records. Here are a few things to check:

Ensure you’re using the correct AWS Access Key and Secret Key. You can find your Access Key and Secret Key in the AWS Management Console under IAM (Identity and Access Management). You can check this documentation for creating and managing Access keys for IAM users: Managing access keys for IAM users

Initialize s3 client

use Aws\S3\S3Client;

$s3Client = new S3Client([
    'version' => 'latest',
    'region' => 'eu-west-2', 
    'credentials' => [
        'key' => 'your_access_key',
        'secret' => 'your_secret_key',
    ],
]);

Here is an example from the documentation:

  1. https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
  2. https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-presigned-url.html

Permissions:

Verify that the Access Key has the necessary permissions to perform the “GetObject” operation on the specified S3 bucket. Make sure the policy associated with the IAM user which has the Access Key allows the required actions (e.g., s3:GetObject).

Region:

Confirm that the region specified ('eu-west-2' in your code) matches the actual region where your S3 bucket is located. If your bucket is in a different region, update the region accordingly.

profile picture
answered 15 days ago
profile picture
EXPERT
reviewed 15 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions