Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have established an AWS acct. and am trying to do my first programmatic PUT into S3. I have used the console to create a bucket and put things there. I have also created a subdirectory (myFolder) and made it public. I created my .aws/credentials file and have tried using the sample codes but I get the following error:

Error executing "PutObject" on "https://s3.amazonaws.com/gps-photo.org/mykey.txt"; AWS HTTP error: Client error: PUT https://s3.amazonaws.com/gps-photo.org/mykey.txt resulted in a 403 Forbidden response: AccessDeniedAccess DeniedFC49CD (truncated...) AccessDenied (client): Access Denied - AccessDeniedAccess DeniedFC49CD15567FB9CD1GTYxjzzzhcL+YyYsuYRx4UgV9wzTCQJX6N4jMWwA39PFaDkK2B9R+FZf8GVM6VvMXfLyI/4abo=

My code is

<?php

// Include the AWS SDK using the Composer autoloader.
require '/home/berman/vendor/autoload.php';
use AwsS3S3Client;
use AwsS3ExceptionS3Exception;
$bucket = 'gps-photo.org';
$keyname = 'my-object-key';
// Instantiate the client.
$s3 = S3Client::factory(array(
    'profile' => 'default',
    'region' => 'us-east-1',
    'version' => '2006-03-01'
));
try {
    // Upload data.
    $result = $s3->putObject(array(
        'Bucket' => $bucket,
        'Key'    => "myFolder/$keyname",
        'Body'   => 'Hello, world!',
        'ACL'    => 'public-read'
    ));
    // Print the URL to the object.
    echo $result['ObjectURL'] . "
";
} catch (S3Exception $e) {
    echo $e->getMessage() . "
";
}

If anyone can help me out, that would be great. Thanks. --Len

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
711 views
Welcome To Ask or Share your Answers For Others

1 Answer

It looks like the same issue I ran into. Add a AmazonS3FullAccess policy to your AWS account.

  • Log into AWS.
  • Under Services select IAM.
  • Select Users > [Your User]
  • Open Permissoins Tab
  • Attach the AmazonS3FullAccess policy to the account

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...