Amazon DynamoDB InvalidSignatureException - php

From this code I'm getting the error below
require "vendor/autoload.php";
use Aws\Common\Aws;
use Aws\DynamoDb\DynamoDbClient;
use Aws\DynamoDb\Enum\ComparisonOperator;
use Aws\DynamoDb\Enum\KeyType;
use Aws\DynamoDb\Enum\Type;
$aws = Aws::factory(array(
'key' => '[clipped]',
'secret' => '[clipped]',
'region' => Region::US_WEST_1
));
$client = $aws->get("dynamodb");
$tableName = "ExampleTable";
$result = $client->createTable(array(
"TableName" => $tableName,
"AttributeDefinitions" => array(
array(
"AttributeName" => "Id",
"AttributeType" => Type::NUMBER
)
),
"KeySchema" => array(
array(
"AttributeName" => "Id",
"KeyType" => KeyType::HASH
)
),
"ProvisionedThroughput" => array(
"ReadCapacityUnits" => 5,
"WriteCapacityUnits" => 6
)
));
print_r($result->getPath('TableDescription'));
I'm getting the following error when trying to add a table into AWS's DynamoDB.
PHP Fatal error: Uncaught Aws\\DynamoDb\\Exception\\DynamoDbException: AWS Error Code:
InvalidSignatureException,
Status Code: 400,
AWS Request ID: [clipped],
AWS Error Type: client,
AWS Error Message: Signature expired: 20130818T021159Z is now earlier than
20130818T021432Z (20130818T022932Z - 15 min.),
User-Agent: aws-sdk-php2/2.4.3 Guzzle/3.7.2 curl/7.21.6 PHP/5.3.6-13ubuntu3.9\n thrown in
/var/www/vendor/aws/aws-sdk-php/src/Aws/Common/Exception/NamespaceExceptionFactory.php on
line 91
So far I've:
Checked to see if Authentication Key and Secret Key were correct, they were.
Updated cURL
When I put false authentication permissions in, the error didn't change.

It seems that your local system time might be incorrect. I've had a similar problem with AWS S3, where my system clock was skewed by 30 mins.
If you're running ubuntu, try updating your system time:
sudo ntpdate ntp.ubuntu.com

You can also restart your date service to solve the problem if you've already got ntpdate installed.
sudo service ntpdate stop
sudo service ntpdate start

If you are using docker-machine on Mac, you can resolve with this command:
docker-machine ssh default 'sudo ntpclient -s -h pool.ntp.org'

Quick note for vagrant projects: this is usually resolved by vagrant reload.

Not exactly OP question, but this is top google response for "InvalidSignatureException DynamoDB", which has many underlying causes.
For me, it was because my body contained emoji, 100% reproducible. Worked around by encoding the body (in my case stringified json) using encodeURIComponent.

Related

cUrl - Host can not be resolved while ping is working fine

After running an apt upgrade and a restart of my ubuntu server, cUrl (via Guzzle) repots an error that the host cannot be resolved.
cURL error 6: Could not resolve host: xx.xx (see http:\/\/curl.haxx.se\/libcurl\/c\/libcurl-errors.html)
My code is
$client = new Client();
$response = $client->post("https://xx.xx?r=/center/api", [
RequestOptions::HEADERS => [
'X-Requested-With' => 'XMLHttpRequest'
]
]);
This happens randomly and with multiple domains. Meanwhile i was running pings for those domains on the terminal and they were working.
On StackOverflow and Google I could only find solutions that were adding the host to the hosts file but for me that seems to be not a real solution.

AWS EC2 PHP SDK credentials not working

I am trying to create a way to programatically start/stop my EC2 instances. This is the code I am using:
<?php
$ec2 = new \Aws\Ec2\Ec2Client([
'credentials' => [
'key' => 'KEY_HERE',
'secret' => 'SECRET_HERE'
],
'region' => env('AWS_REGION', 'us-west-2'),
'version' => 'latest',
'ua_append' => [
'L5MOD/' . AwsServiceProvider::VERSION,
]
]);
$result = $ec2->describeInstanceStatus([
'InstanceIds' => ['i-c21a366e']
]);
?>
Of course I am using my actual keys instead of 'KEY_HERE' and 'SECRET_HERE'.
I am getting this error as you can see in this screenshot:
I want to mention that if I use the S3 service, everything works fine. I am having this problem with the EC2 service only.
Any idea what could be wrong?
I finally found out what is going on and I was able to fix it.
Looks like AWS is using server clock for authorizing access and I needed to install the ntp service and update it so that the clock is properly synced.
I installed the ntp server by running:
sudo apt-get install ntp
Then I updated the services with these commands:
sudo service ntp stop
sudo ntpd -gq
sudo service ntp start
And problem was fixed.

Composer update ran via puppet times out

I'm using composer to manage dependencies. And basically want I want to do is automatically run composer update in puppet config when vagrant up is running.
I'm using puphpet to generate puppet files for vagrant.
I added composer::exec section in this code in the default.pp file:
if $php_values['composer'] == 1 {
class { 'composer':
target_dir => '/usr/local/bin',
composer_file => 'composer',
download_method => 'curl',
logoutput => true,
tmp_path => '/tmp',
php_package => "${php::params::module_prefix}cli",
curl_package => 'curl',
suhosin_enabled => false,
}
composer::exec { 'composer-update':
cmd => 'update',
cwd => '/var/www/myproject'
}
}
Some times I'm getting this error in output:
Error: Command exceeded timeout
Error: /Stage[main]//Composer::Exec[composer-update]/Exec[composer_update_composer-update]/returns: change from notrun to 0 failed: Command exceeded timeout
And there is no timeout property in puppet composer.
How to solve it?
Take a look at http://docs.puppetlabs.com/references/latest/type.html#exec-attribute-timeout - it is possible to set a timeout for an exec resource. If the puppet composer module does not provide an option to override that, it really should IMO. And if by a chance it is composer itself that's timing out, not puppet exec, you'd wanna try
export COMPOSER_PROCESS_TIMEOUT=600

Error! Symfony2 with KNP Snappy Bundle & WKHTML2PDF

When I go to /fileDownload I receive a 500 Internal Server Error - RuntimeException:
The process stopped because of a "0" signal.
Controller Action:
public function fileAction()
{
$html = $this->render('MyBundle:Downloads:file.html.twig', array(
'fileNumber' => '1234'
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
}
I've used terminal commands for WKHTMLTOPDF and it has successfully generated the PDF. It just will not work in Symfony2 app.
In my config.yml:
knp_snappy:
pdf:
enabled: true
binary: /usr/local/bin/wkhtmltopdf
options: []
I'm assuming Symfony is issuing an exec() at some stage. You need to get the exact command line error returned. The fact it works for you in a terminal session doesn't necessarily mean it will work when a different user/process is running it.
Check permissions on wkhtmltopdf that apache or whoever is running your web server has access to run the command.
Also, check this question out wkhtmltopdf: cannot connect to X server and also the first post here: http://geekisland.org/index.php?m=05&y=11&entry=entry110518-114630
X Server is required to run certain builds of wkhtmltopdf and it is not present when running via cron or from within an apache process. If this is the case you need to use the bash wrapper in the first link above.
Be sure that wkhtmltopdf is indeed in the folder you specify, with correct permissions: /usr/local/bin/wkhtmltopdf
I am successfully using KNP Snappy Bundle with Symfony 2.0, try using RenderView instead of render when generating the html (check my code that is working):
Controller:
$html = $this->renderView('YOPYourOwnPoetBundle:thePoet:poemPDF.html.twig', array(
'poem' => $customizedPoem,
'fontType' => $fontType,
'fontSize' => $formData['fontSize'],
'fontWeight' => $fontWeight,
'fontStyle' => $fontStyle,
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="'.$session->get('poemTitle').'.pdf"',
)
);
I had this same issue and i finally solved it, my advice is if you installed the wkhtmltopdf lib from your OS repos then remove it, and download the static version from the google code website, and don't use version 11rc, use the version 9 static lib, it's the one that worked with me.
http://code.google.com/p/wkhtmltopdf/downloads/list
It looks like the selinux is blocking your command, I had the same issue once but I solved it by disabling the SELinux and now I'm able to generate the pdf file using wkhtmltopdf+php.
exec("/usr/local/bin/wkhtmltopdf http://www.google.com /var/www/html/google.pdf");
To disable selinux run setenforce 0,
try again and see if it works.
Re-enable it with setenforce 1
But disabling selinux is not the best solution for this, you need to extend it instead using audit2allow, it will automatically create a custom policy module that will resolve this issue,
First install audit2allo if not already installed
yum -y install policycoreutils-python
grep httpd_t /var/log/audit/audit.log | audit2allow -m httpdlocal > httpd.te
checkmodule -M -m -o httpdlocal.mod httpd.te
semodule_package -o httpdlocal.pp -m httpdlocal.mod
semodule -i httpdlocal.pp
try again and see if it works
I experienced the same issue on same scenario with wkhtmltopdf. And I got rid of with the following command:
setsebool httpd_execmem on

PHP Error Class 'SoapClient' not found

I was trying to install Wordpress on our server to test, but in order to do that I had to upgrade our current PHP version to 5.3. I upgraded our PHP and I am now finding that our Purolator shipping module is no longer working. According to our host support the "purolator.php" file is missing data that the new version of PHP requires. Unfortunately, I can't revert our PHP version back and our programmer is away.
This is the error message I was able to get from our website host support team:
tail /var/www/vhosts/phantomcables.com/statistics/logs/error_log -f
[Thu Jul 19 08:34:28 2012] [error] [client 70.51.168.201] PHP Fatal
error: Class 'SoapClient' not found in
/var/www/vhosts/phantomcables.com/httpdocs/shippings/purolator.php on line
49, referer: https://phantomcables.com/index.php?dispatch=checkout.cart
These are lines 40 to 72:
function createPWSSOAPClient()
{
/** Purpose : Creates a SOAP Client in Non-WSDL mode with the appropriate authentication and
* header information
**/
//Set the parameters for the Non-WSDL mode SOAP communication with your Development/Production credentials
//echo DIR_SHIPPING_FILES."estimatingservice.wsdl";
$url = "https://webservices.purolator.com/PWS/V1/Estimating/EstimatingService.asmx";
$client = new SoapClient( DIR_SHIPPING_FILES."estimatingservice.wsdl",
array (
'trace' => true,
'location' => $url,
'uri' => "http://purolator.com/pws/datatypes/v1",
'login' => PRODUCTION_KEY,
'password' => PRODUCTION_PASS
)
);
//Define the SOAP Envelope Headers
$headers[] = new SoapHeader ( 'http://purolator.com/pws/datatypes/v1', 'RequestContext',
array (
'Version' => '1.0',
'Language' => 'en',
'GroupID' => 'xxx',
'RequestReference' => 'Rating Example'
)
);
//Apply the SOAP Header to your client
$client->__setSoapHeaders($headers);
return $client;
}
Any help would be greatly appreciated.
It seems like you did not have installed the php-soap package on your server.
Type
phpinfo();
in your code and check if 'Soap Client' is 'enabled'.
If not, I don't know your distribution and package manager, but here is the code for Fedora I use:
$ yum install php-soap
I suggest to do it with your programmer back or a sys admin by your sides, you never know what could happen. A backup is also useful before any installation!
You will need to add (or remove any comment characters before)
extension=soap.so
to your php.ini file, and then restart the web server.
If you are having trouble finding your php.ini file, create a page with the following:
<?php phpinfo();
and load that file in your browser.
On some systems, this setting may not actually live in php.ini. For example, if you are using Zend Server, the setting would live in /usr/local/zend/etc/conf.d/soap.ini.
So we reverted back to an older version of PHP, and re-enabled SOAP. apparently that was the issue, not sure why that didn't work with the newer version of PHP.
Again thank you for all of your help. This is a great community.
It is already posted here
Do the following:
Locate php.ini in your apache bin folder, I.e Apache/bin/php.ini
Remove the ; from the beginning of extension=php_soap.dll
Restart your Apache server
Look up your phpinfo(); again and check if you see a similar picture to the one above
If you do, problem solved!
Enable the SOAP extension, require it in your composer.json like so:
{
"require": {
"ext-soap": "*"
}
}

Categories