kennu / simply-static-s3

Fork of WordPress simply-static plugin with S3 support
GNU General Public License v2.0
23 stars 17 forks source link

S3Exceptions when publishing #1

Open insanityfarm opened 8 years ago

insanityfarm commented 8 years ago

When I click Generate Static Files, I'm taken to a blank screen (the WP header + sidebar render, but there's no page content). No files are sent to my bucket.

I checked my Apache error log and found this:

PHP Fatal error: Uncaught exception 'S3Exception' with message 'S3::putObject(): [PermanentRedirect] The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.' in /var/www/html/mysite/wp-content/plugins/simply-static-s3/includes/libraries/S3.php:707\nStack trace:\n#0 /var/www/html/mysite/wp-content/plugins/simply-static-s3/includes/libraries/S3.php(707): S3::__triggerError('S3::putObject()...', '/var/www/html/m...', 707)\n#1 /var/www/html/mysite/wp-content/plugins/simply-static-s3/includes/class-simply-static-archive-creator.php(257): S3::putObject(Array, 'mybucketnam...', 'mysite/wp-js...', 'public-read')\n#2 /var/www/html/mysite/wp-content/plugins/simply-static-s3/includes/class-simply-static.php(257): Simply_Static_Archive_Creator->publish_to_s3('mybucketnam...', 'MYAWSACCESSKEYID...', 'MyAWSSecretAccessKey...')\n#3 [internal function]: Simply_Static->display_generate_page('')\n#4 /var/www/html/mysite/wp-includes/plugin.php(525): in /var/www/html/mysite/wp-content/plugins/simply-static-s3/includes/libraries/S3.php on line 707, referer: http://www.mydomain.com/mysite/wp-admin/admin.php?page=simply-static-s3

It looks like I'm not referencing my bucket correctly. It's defined in the plugin settings as "mybucketname". I tried changing it to the bucket endpoint instead: "mybucketname.s3-website-us-east-1.amazonaws.com". This caused a new error on generation:

PHP Fatal error: Uncaught exception 'S3Exception' with message 'S3::putObject(): [NoSuchBucket] The specified bucket does not exist' in /var/www/html/mysite/wp-content/plugins/simply-static-s3/includes/libraries/S3.php:707\nStack trace:\n#0 /var/www/html/mysite/wp-content/plugins/simply-static-s3/includes/libraries/S3.php(707): S3::__triggerError('S3::putObject()...', '/var/www/html/m...', 707)\n#1 /var/www/html/mysite/wp-content/plugins/simply-static-s3/includes/class-simply-static-archive-creator.php(257): S3::putObject(Array, 's3-website-us-e...', 'mysite/index...', 'public-read')\n#2 /var/www/html/mysite/wp-content/plugins/simply-static-s3/includes/class-simply-static.php(257): Simply_Static_Archive_Creator->publish_to_s3('s3-website-us-e...', 'MYAWSACCESSKEYID...', 'MyAWSSecretAccessKey...')\n#3 [internal function]: Simply_Static->display_generate_page('')\n#4 /var/www/html/mysite/wp-includes/plugin.php(525): call_user_func_array(Array, Array)\n#5 /var/www/html/mysite/wp-admin/admin.php(236): doaction('toplevel in /var/www/html/mysite/wp-content/plugins/simply-static-s3/includes/libraries/S3.php on line 707, referer: http://www.mydomain.com/mysite/wp-admin/admin.php?page=simply-static-s3

It's not clear to me how I'm supposed to reference my bucket. I've tried every permutation I can think of including...

I also tried removing the region (leaving "s3-website.amazonaws.com") and replacing the region portion with "us-standard". All of my attempts resulted in one of the two errors above. I don't know what else I can try.

I'm new to S3, so apologies if my questions are ignorant. Actually I hope they are – that would probably mean an easy fix!

insanityfarm commented 8 years ago

I identified the problem... it's on line 251 of class-simply-static-archive-creator.php. You hard-coded a region of "s3-eu-west-1.amazonaws.com" into the S3 object instantiation. So I had the bucket name right the first time, when I referred to it as just "mybucketname". But my bucket is in the "s3-website-us-east-1.amazonaws.com" region, which explains the PermanentRedirect error.

Replacing the region string in the class file fixed the problem for me. I hope this is useful for someone else as well.

insanityfarm commented 8 years ago

Quick addendum to what I posted earlier: My solution of replacing the "region" (actually the endpoint but I'm still learning AWS vocabulary) solved my original problem but led to another. My requests were now throwing "[405] Unexpected HTTP status" exceptions.

The fix for that, it turns out, was to remove the endpoint from the declaration entirely and use the S3 class's default of "s3.amazonaws.com" instead. Apparently the endpoint I was using leads to a different API than this one, and that one doesn't support inbound PUT requests. After that change everything seems to be working as expected.

kennu commented 8 years ago

Thanks for your notes @insanityfarm. I'll keep this issue open to remind me to make the endpoint configurable and to test it with multiple regions.

Skeyelab commented 8 years ago

has this been fixed in the current version of this plugin?

-edit: It seems "no" am I correct in understanding the fix is to change line 251 to: $s3 = new S3( $aws_access_key_id, $aws_secret_access_key, false, 's3.amazonaws.com' );

kennu commented 8 years ago

Sorry you're right, I haven't had time to check and fix the issue. My own buckets are in eu-west-1 and I would need to test this in both regions, but I haven't used the plugin myself for a while.

bmcgair commented 7 years ago

@Hmm... I tried this plugin out a couple of months ago and it seemed to work fine, but now when I hit "generate static files" it spins for a while and then I get a 504 error:

The page isn't working

took too long to respond. No other logging or debug, even with wp debug set to on. I have the patch suggested above installed. It seems to have worked *once* and published an initial version of the site to my bucket, but not on subsequent tries.
kenzik commented 7 years ago

@kennu - See #3 and related PR that can be merged.

@insanityfarm - If needed, you can grab my branch diff from PR4.