ERROR: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method.

If you are using the AWS route53 class and you stumbled upon the error below:

object(stdClass)[4]
  public 'error' => 
    array (size=3)
      'curl' => boolean false
      'Error' => 
        array (size=3)
          'Type' => string 'Sender' (length=6)
          'Code' => string 'SignatureDoesNotMatch' (length=21)
          'Message' => string 'The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.' (length=178)
      'RequestId' => string '078cbec9-10a2-11e7-a36b-7bfec70d5319' (length=36)
  public 'code' => int 403

Here’s what you can do, check that the credentials in your code is correct. Check both AWS Key and AWS Secret. Also ensure that forward slash at the end of the secret is present if and only if your AWS must have it.

ERROR: Unable to determine service/operation name to be authorized

If you are using the AWS route53 class and you stumbled upon the error below:

  public 'error' => boolean false
  public 'body' => 
    object(SimpleXMLElement)[5]
      public 'Message' => string 'Unable to determine service/operation name to be authorized' (length=59)
  public 'code' => int 403

Here’s what you can do. Check your hosted zone id. It should be in this form /hostedzone/Z8HJDGKXCKSH35. Ensure to include the word /hostedzone/ otherwise you’ll encounter the error above.

Copy a file content to a gz file

Here’s a code to create and write the content from a url to a gz file.

In this example, we are copying the content of an rss feed to a gz file. RSS Feed is usually an xml file that’s why we are adding .xml before the .gz extension.

$content = 'http://example.com/rss/feed';
$gz = gzopen ( 'filename.xml.gz', 'w9' );
gzwrite ( $gz, $content );
gzclose ( $gz ); 

Workaround in getting image details that returns a 403 error.

If you are trying to pull data that returns a 403 error then here’s the workaround for that. Use stream_context_create and use the result as a parameter in the file_get_contents.

In this example, it is trying to pull the image size of the image from the $url variable.

$ctx = stream_context_create(array(
        'http' => array('timeout' => 25, 'protocol_version' => 1.1,'user_agent' => 'My User Agent/1.0'),
        'https' => array('timeout' => 25, 'protocol_version' => 1.1,'user_agent' => 'My User Agent/1.0')
    ));

$dimension = getimagesizefromstring(  file_get_contents($url, 0, $ctx) );