This is a very strange problem. I have just setup my application on Elastic Beanstalk, the connection which I made with Amazon DynamoDB is working fine but when i made a connection through an AJAX call , it is not connecting and also it is not showing any error. Please help me guys
I have tried changing my role from aws-elasticbeanstalk-service-role to aws-elasticbeanstalk-ec2-role. But still no luck!
I am using the below code to make the connection -
$credentials = new \Aws\Credentials\Credentials(AWS_KEY, AWS_SECRET);
$client = new \Aws\DynamoDb\DynamoDbClient([
'region' => 'us-west-2',
'version' => 'latest',
'credentials' => $credentials
]);
Related
today my web site which usually auto logs to aws s3 by php, can't connect anymore; the code hasn't changed at all.
$s3Client = new S3Client([
'region' => 'eu-west-1',
'version' => 'latest',
'credentials' => [
'key' => $key,
'secret' => $secret,
],
'http' => [
'verify' => '../ssl_crt/cacert.pem'
]
]);
//echo var_dump($s3Client);
//Listing all S3 Bucket
$result = $s3Client->listBuckets();
the code above which has worked fine till yesterday now gets tomeout connection and therefore fails listing buckets.
I have read amazon has changed something in the permissions/policy, but I can't find how this can be related to PHP s3Client... maybe I could just change some setting in AWS S3 control panel, but I can't figure out what...Has anyone experienced the same issue
When I deploy my application to a EC2 instance, it fails to fetch messages from my SQS queue. And instead throws an exception with the status code 403 Forbidden, access to the resource {sqs queue} is denied. However, when I run the same code from my local environment my application can fetch messages from the SQS queue.
My application uses the symfony framework and passes pre-configured AWS credentials, for a user who has access to this queue, from the parameters.yml into \Aws\Sqs\SqsClient().
If on the EC2 instance I run aws configure and configure the aws cli with the same credentials the application can pull messages from the SQS queue. I am concerned here because it is like the aws sdk is overriding the credentials I pass it.
As a example the following code even with hard coded parameters which I have checked are valid credentials, returns a 403 when ran on a EC2 instances.
$sqs = new \Aws\Sqs\SqsClient([
[
'key' => '{my key}',
'secret' => '{my secret}'
],
'region' => 'us-east-1',
'version' => 'latest'
]);
$response = $sqs->receiveMessage([
'QueueUrl' => 'https://sqs.us-east-1.amazonaws.com/{my account}/{my queue}'
]);
Does anyone have any suggestions about what may be happening here?
Try with credentials key in config.
$sqs = new \Aws\Sqs\SqsClient([
'credentials' => [
'key' => '{my key}',
'secret' => '{my secret}',
],
'region' => 'us-east-1',
'version' => 'latest'
]);
$response = $sqs->receiveMessage([
'QueueUrl' => 'https://sqs.us-east-1.amazonaws.com/{my accoun}/{my queue}'
]);
This might help you to debug your issue.
Run aws sqs list-queues on command line. If your queue not listed in the result set, that means your AWS key doesn't have permission.
Run aws sqs receive-message --queue-url <queue_url> where queue_url is your queue's complete url received from step 1. You should see all your messages in the queue.
If there are no errors in above both steps, there might be an issue in your application end.
It's a bad practice to store AWS credentials in EC2 instances, It's much better to create an IAM role with sqs:receiveMessage permission then attach that IAM role to your EC2 instance.
I am trying to check bucket existence on Amazon S3 using below code:
$credentials = new Aws\Common\Credentials\Credentials($creds['access_key_id'], $creds['secret_access_key']);
$client = Aws\S3\S3Client::factory(array( 'credentials' => $credentials ) );
if( ! $client->doesBucketExist($creds['bucket']) ) {
throw new Exception("Bucket (" . $creds['bucket'] . ") does not exist.");
}
It is working on localhost (wamp) but when I tried this on server it is not working. I am getting following error:
Missing required client configuration options: region: (string) A "region" configuration value is required for the "s3" service (e.g., "us-west-2"). A list of available public regions and endpoints can be found at http://docs.aws.amazon.com/general/latest/gr/rande.html. version: (string) A "version" configuration value is required. Specifying a version constraint ensures that your code will not be affected by a breaking change made to the service. For example, when using Amazon S3, you can lock your API version to "2006-03-01". Your build of the SDK has the following version(s) of "s3": * "2006-03-01" You may provide "latest" to the "version" configuration value to utilize the most recent available API version that your client's API provider can find. Note: Using 'latest' in a production application is not recommended. A list of available API versions can be found on each client's API documentation page: http://docs.aws.amazon.com/aws-sdk-php/v3/api/index.html. If you are unable to load a specific API version, then you may need to update your copy of the SDK.
I don't know why it is not working on server but same code is working on localhost.
I had the same problem and I needed to clear my config cache to fix it.
$ artisan config:clear
Set region explicitly when creating s3 client instead of relying on defaults.
use Aws\Credentials\Credentials;
use Aws\S3\S3Client;
$result = $stsClient->getSessionToken();
$credentials = new Credentials(
$result['Credentials']['AccessKeyId'],
$result['Credentials']['SecretAccessKey'],
$result['Credentials']['SessionToken']
);
$s3Client = new S3Client([
'version' => '2006-03-01',
'region' => 'us-west-2',
'credentials' => $credentials
]);
Check .env file variables are matching with filesystems.php
's3' => [
'driver' => 's3',
'key' => env('S3_KEY'),
'secret' => env('S3_SECRET'),
'region' => env('S3_REGION'),
'bucket' => env('S3_BUCKET'),
],
1) Ensure you have S3_KEY, S3_SECRET, S3_REGION, S3_BUCKET etc configured in your .env file
2) Your environment file might have changed after the autoload/caches were generated. Run:
php artisan config:cache
I am in need of an AWS dynamodb as the backend for my project.. I have already completed the below tasks:
established jar for dynamodb local server to start listening
downloaded PHP SDK from AWS
created an iam user from AWS console and copied the credentials.ini file into .aws folder
Executed the php script to connect my local dynamodb and create the table.
After all those tasks have been completed, localhost gives me a message stating the 'table created'. However am not able to find my table in the AWS console. What could be the problem?.
Am I doing it correctly? .. can someone please shed some light on this?
Here's my connection through PHP:
$client = new Aws\Sdk([
//'profile' => 'default',
'region' => 'us-west-2',
'version' => 'latest',
'endpoint' => 'http://localhost:8000',
'credentials' => [
'key' => '',
'secret' => '']
]);
Firstly, when you are using local host, the table would be created in your local machine (i.e. not in AWS). You have mentioned AWS console, I understood that as you are looking for the table on "AWS Management Console". When you use endpoint as "http://localhost:8000", the API will never interact with actual AWS.
It refers to the local dynamodb instance.
To check the table on local dynamodb instance:-
1) If you have AWS CLI installed on your system, you can check the existence of the table using below command.
aws dynamodb describe-table --table-name yourTableName --endpoint-url http://localhost:8000
2) Otherwise, go to http://localhost:8000/shell/
var docClient = new AWS.DynamoDB({
region: 'us-east-1',
endpoint: "http://localhost:8000"
});
var params = {TableName:'yourTableName'};
docClient.describeTable(params, function(err, data) {
if (err) {
console.log(err, err.stack);
} else {
console.log(data);
// php.var_dump(data);
}
});
If table exists:-
It will show the definition of the table
If table doesn't exists:-
You will get the below error message.
"message":"Cannot do operations on a non-existent table"
I have imported 'aws-autoloader.php' and used AWS-SDK php library
$sns = SnsClient::factory(array('key' => "******",
'secret' => "*******",
'region' => "us-east-1"));
But I cant able to get any responds. I already used this key and secret in AWS S3 but here its not working help me regarding this.