Skip to content
Advertisement

Response logging in AWS PHP SDK v3

In v2 of the AWS PHP SDK, I was able to setup logging of request and response information by simply doing this:

JavaScript

In v3, I cannot seem to find the solution. Middlewares do not seem helpful as they only fire before the request is sent, and thus I cannot access the response HTTP code.

Guzzle v6 has this feature built into its Middlewares, but I do not know how to get it to work with the aws-php-sdk. https://github.com/guzzle/guzzle/blob/master/src/Middleware.php#L180

The closest I got was this:

JavaScript

However, while the logging works, doesObjectExist() now returns the incorrect value because this handler does not throw an exception for 404, which the aws-php-sdk expects to happen. Some other simple requests like uploading to S3 seemed to work at first glance. Not sure where else there could be issues with this method.

Advertisement

Answer

The handler used in the SDK is a bit different from the one used in Guzzle. You’re creating a Guzzle handler correctly, and to pass that into the SDK, you would need to create an adapter like so:

JavaScript

The GuzzleHandler object converts HTTP errors to exceptions.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement