Any body knows how to solve this
Error message after trying to convert the image to ami
Note (I already try to import via command line and it's working good)
I'm trying to convert image from row to ami using laravel 8
Here is the information
1.) "aws/aws-sdk-php": "^3.231"
2.) php 8
3.) my code to process the conversion
public function startConversion(string $s3DiskImageName, string $description): void{
$client = ImportExportClient::factory(array(
'credentials' => array(
'key' => config('filesystems.disks.s3.key'),
'secret' => config('filesystems.disks.s3.secret'),
),
'region' => config('filesystems.disks.s3.region'),
'version' => 'latest'
));
$bucket = config('filesystems.disks.s3.bucket');
$client->createJob([
'JobType' => 'Import',
'ValidateOnly' => false,
'Manifest' => json_encode([
[
'Description' => "$s3DiskImageName - $description",
'Format' => 'raw',
'Url' => 's3:://'.$bucket .'/'.$s3DiskImageName
]
])
]);
}
Thanks in advance!
Related
I have tried to read content from a s3 object through the below code.
$content = $s3Client->getObject(
array(
'Bucket'=> $bucketName,
'Key' => $pathToObject,
'ResponseContentType' => 'text/plain',
)
);
And I got below response
GuzzleHttp\Psr7\Stream Object (
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #87
[size:GuzzleHttp\Psr7\Stream:private] =>
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
Any help will be appreciated to read object content in S3.
Actually its return Psr7\Stream object.
So if we need to get contents from PSR Stream we have to call getContents() method from the object.
<?php
$s3Client = new Aws\S3\S3Client(array(
'stats' => TRUE,
'http' => array(
'verify' => FALSE,
'connect_timeout' => 30
),
'version' => 'latest'
));
$result = $s3Client->getObject(array(
'Key' => $filename,
'Bucket' => $bucketName
));
echo $result['Body']->getContents();
//Also you can get metadata like this print_r($result['Body']->getMetadata());
Hope this will help someone who is actually using SDK version 3.
Specification here https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-GuzzleHttp.Psr7.Stream.html
I am trying to use query string structure in drupal services API. it's not working for me.
I have also search most of the solutions, but all failed.
here is m drupal code:
function rapid_services_resources() {
$resources = array(
'get_data' => array(
'operations' => array(
'retrieve' => array(
'help' => t('Gets user email of uid passed.'),
'callback' => 'my_module_get_user_email',
'args' => array(
array(
'name' => 'nid',
'type' => 'int',
'description' => 'The display ID of the view to get.',
'source' => array('param' => 'nid'),
'optional' => TRUE,
'default value' => 'default',
),
),
'access arguments' => '_blog_access_provide_access',
'access callback' => '_blog_access_provide_access',
//~ 'access arguments append' => FALSE,
),
),
),
);
return $resources;
}
function _blog_access_provide_access() {
return TRUE;
}
function my_module_get_user_email($nid){
var_dump($args);die;
}
I want url like this.:
http://localhost/drupaltest/rapidapi/get_data/?nid=111
Please let me know where i did wrong.
thanks in advance.
Hi here are to reference that will be useful
http://pingv.com/blog/an-introduction-drupal-7-restful-services
https://www.drupal.org/node/783460
Also I am not sure about the query string, but for the retrieve operation you can set it as part of the url
ex:
http://localhost/drupaltest/rapidapi/get_data/<nid should be here>
http://localhost/drupaltest/rapidapi/get_data/111
Also using the source path as source
'source' => array('path' => '0'),
I would think that source param only works for an index operation and not retrieve
I have deployed a Yii2 based app onto AWS Elastic Beanstalk, also I have created the RDS instance with a database (it already has tables) on Elastic Beanstalk. However I received this error: "SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known"
All the files are uploaded correctly to the AWS instance.
The file /common/config/main-local.php has:
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=',
'dsn' => 'mysql:host=RDS_HOSTNAME:RDS_PORT;dbname=RDS_DB_NAME',
'username' => 'RDS_USERNAME',
'password' => 'RDS_PASSWORD',
'charset' => 'utf8',
],
What could be wrong? Thanks.
I am guessing that you want pass db information through environment variables. You may want to try to revise the code as below.
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=',
'dsn' => 'mysql:host='.$_SERVER['RDS_HOSTNAME'].':'.$_SERVER['RDS_PORT'].';dbname='.$_SERVER['RDS_DB_NAME'],
'username' => $_SERVER['RDS_USERNAME'],
'password' => $_SERVER['RDS_PASSWORD'],
'charset' => 'utf8',
],
You can reference http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.RDS.html#rds-external-ec2classic in To configure environment properties section to configure your environment variables. Hope this works.
You have 2 times your 'dsn' line and maybe the first one survives, so changing your config to this should work:
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=RDS_HOSTNAME:RDS_PORT;dbname=RDS_DB_NAME',
'username' => 'RDS_USERNAME',
'password' => 'RDS_PASSWORD',
'charset' => 'utf8',
],
(In addition I hope you are aware that you have to change RDS_* parameters :D)
Following this, I used runInstances method like the following to launch and instance:
$new_instance_config = array(
'DryRun' => false,
'ImageId' => AMI_ID,
'MinCount' => 1,
'MaxCount' => 1,
'InstanceType' => 't1.micro',
'Placement' => array(
'AvailabilityZone' => AVAILABILITY_ZONE,
),
'Monitoring' => array(
'Enabled' => false,
),
'NetworkInterfaces' => array(
array(
'SubnetId' => SUBNET_ID,
'DeviceIndex' => 0,
'AssociatePublicIpAddress' => true,
'DeleteOnTermination' => true,
'Groups' => unserialize(SECURITY_GROUP_IDS)
)
)
);
$res = $this->ec2Client->runInstances($new_instance_config);
echo json_encode($res);
However this only prints blank object {} even though if I login to the AWS console, I can see the instance launched.
I need to access some information like the AMI ID of the launched instance. Am I missing something?
See Modeled Responses
Try:
$res['Instances']
or
$res->get('Instances')
I have a ZF2 2.1.3 app with Doctrine 2.
I installed using composer:
"zendframework/zendframework": "2.*"
,"doctrine/doctrine-orm-module": "dev-master"
A create a file config/autoload/database.local.php with the following:
return array(
'doctrine' => array(
'connection' => array(
// Default connection name
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'localhost',
'port' => '3306',
'dbname' => 'zf2-experimental',
'user' => 'root',
'password' => '',
),
),
),
),
);
I create my entity Bar under Foo module (src/Business/Entity/Bar.php) and configure it on module.config.php like this:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Business/Entity'),
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Business\Entity' => __NAMESPACE__ . '_driver',
),
),
),
),
Ok! It's exactly at Sam says here!
Then I create a simple Foo entity and run the doctrine cli tool:
c:\wamp\www\zf2-Experimental>.\vendor\bin\doctrine-module.bat orm:validate-schema
[Mapping] OK - The mapping files are correct.
[PDOException]
SQLSTATE[28000] [1045] Access denied for user 'username'#'localhost' (using password: YES)
orm:validate-schema
c:\wamp\www\zf2-Experimental>
Looks like the cli tool can get my connection parameters in my config/autoload/database.local.php!
On Application index I tested my config:
$config = $this->getServiceLocator()->get('config');
\Zend\Debug\Debug::dump($config['doctrine']['connection']['orm_default']);
And this returned:
array (size=4)
'configuration' => string 'orm_default' (length=11)
'eventmanager' => string 'orm_default' (length=11)
'params' =>
array (size=5)
'host' => string 'localhost' (length=9)
'port' => string '3306' (length=4)
'user' => string 'root' (length=4)
'password' => string '' (length=0)
'dbname' => string 'zf2-experimental' (length=16)
'driverClass' => string 'Doctrine\DBAL\Driver\PDOMySql\Driver' (length=36)
Someone can, please, help me?! :)
Thanks you all!
Well, I waste a lot of time trying to solve this and finally did.
I forgot to mention that I using ZF1 environment-specific configurations style!
You can see here!
I create my database config file in the following structure (I didn't mention this before, because I thought It wouldn't interfere on the question):
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
// Here! My config path is config/autoload/app_env/development/
'config/autoload/app_env/' . (getenv('APPLICATION_ENV') ?: 'production') . '{,*.}.local.php',
),
So, my database configs actually are in config/autoload/app_env/development/database.local.php!
When I copy-paste the file to config/autoload/database.local.php my CLI Tool works!
But WHY? Why the Cli Tool can't look for the config file inside another directory?
There is a way to work with sub-folders?
Thanks for the help!