glacier php expedited download - php

I am trying to download my archive from Amazon Glacier using expedited option. I'm doing it via PHP with PHP SDK3. I have a little problem. I've launched job to get ArchiveID:
$credentials = new Credentials('GLA_AWS_KEY', 'GLA_AWS_SECRET');
$client = new GlacierClient(array(
'version' => 'latest',
'credentials' => $credentials,
'region' => 'GLA_AWS_REGION'
));
$result = $client->initiateJob(array(
'vaultName' => 'GLA_AWS_VAULT',
'jobParameters' => [
'Type' => 'archive-retrieval',
'ArchiveId' => $archiveId,
]
));
$jobid = $result->get('jobId');
How can you recover the file in expedited mode?
Thanx for any help ;D

Finally I found the answer. For anyone interested on it.
$result = $client->initiateJob(array(
'vaultName' => 'GLA_AWS_VAULT',
'jobParameters' => [
'Type' => 'archive-retrieval',
'ArchiveId' => $archiveId,
'Tier' => 'Expedited'
]
));
We need to add the Tier as Expedited. The download time reduces to 5 minuts more or less.

Related

How to setup amazon timestream in php?

I have found the documentation for it here. I have PHP SDK installed. Now when I go through the documents there is not so much in detail about the PHP one. I have the following questions:
Here how can I specify the $client
$result = $client->createDatabase([
'DatabaseName' => '<string>', // REQUIRED
'KmsKeyId' => '<string>',
'Tags' => [
[
'Key' => '<string>', // REQUIRED
'Value' => '<string>', // REQUIRED
],
// ...
],
]);
Is there any good documents or videos regarding the timestream in PHP from where I can get some help.
There are two client classes. One for writing and one for reading.
TimestreamWriteClient
https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.TimestreamWrite.TimestreamWriteClient.html
and
TimestreamQueryClient
https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.TimestreamQuery.TimestreamQueryClient.html
You can use the function createTimestreamQuery and createTimestreamWrite on the $sdk object to instantiate those classes.
A sample Timestream client and query below.
// Create client
$client = new \Aws\TimestreamQuery\TimestreamQueryClient([
'version' => 'latest',
'region' => AWS_REGION, /* eg: eu-west-1 */
'endpoint' => AWS_TIMESTREAM_ENDPOINT, /* eg: https://query-cell3.timestream.eu-west-1.amazonaws.com */
'credentials' => new \Aws\Credentials\Credentials(AWS_KEY, AWS_SECRET)
]);
// Perform a basic query with the client
$client->query([
'QueryString' => 'select * from "db_timestream"."tbl_usage_logs"',
'ValidateOnly' => true,
]);
If you receive endpoint warning, such as "The endpoint required for this service is currently unable to be retrieved"
You can find endpoint using AWS CLI command,
aws timestream-query describe-endpoints --region eu-west-1
Sample response:
{
"Endpoints": [
{
"Address": "query-cell3.timestream.eu-west-1.amazonaws.com",
"CachePeriodInMinutes": 1440
}
]
}
One can create TimestreamWriteClient and write records in a similar way.
The documentation seems sparse and a bit misleading, to me anyhow.
This is how I got it going for a write client (assuming SDK is installed).
//Create the client
$client = new \Aws\TimestreamWrite\TimestreamWriteClient([
'version' => 'latest',
'region' => 'eu-west-1',
'credentials' => new \Aws\Credentials\Credentials('***KEY***', '***SECRET***')
]);
Note that the 'endpoint' is not specified, as I've seen in some examples. There seems to be some misleading documentation of what the endpoint should be for any given region. The SDK does some magic and creates a suitable endpoint; providing a specific endpoint didn't work for me.
$result = $client->writeRecords(
[
'DatabaseName' => 'testDB',
'TableName' => 'history',
'Records' =>
[
[
'Dimensions' => [
[
'DimensionValueType' => 'VARCHAR',
'Name' => 'Server',
'Value' => 'VM01',
],
],
'MeasureName' => 'CPU_utilization',
'MeasureValue' => '1.21',
'MeasureValueType' => 'DOUBLE',
'Time' => strval(time()),
'TimeUnit' => 'SECONDS',
]
]
]
);
This seems to be the minimum set of things needed to write a record to Timestream successfully. The code above writes one record, with one dimension, in this case, a 'Name' of a 'Server', recording its CPU utilization at time().
Note:
Time is required, although the documentation suggested it is optional.
Time has to be a String.

kinesis "getShardIterator" gets stuck

I have a weird problem when fetching items from kinesis.
So when I have events in the stream, and Im querying for them with the correct timestamp, I get the result.
But if I don't have events in the stream
or
if I'm querying for times where not event are there
The call getShardIterator gets stuck for several minutes.
That's why I added the "timeout" of 2 seconds.
Is there a better way to just get an empty response from kinesis if no events found?
Thanks
<?php
$getKinessisClient = new GetKinessisClient();
$kinesisClient = $getKinessisClient->get([
]);
$params = [
'credentials' => array(
'key' => 'xxxx',
'secret' => 'xxxx',
),
'region' => 'xxxx',
'version' => 'latest',
'http' => [
'timeout' => 2
]
];
$kinesisClient = (new Sdk())->createKinesis($params);
// get all shard ids
$res = $kinesisClient->describeStream([ 'StreamName' => $streamName ]);
$shardIds = $res->search('StreamDescription.Shards[].ShardId');
$foundItems = [];
foreach ($shardIds as $shardId) {
try {
$getShardItParams = [
'ShardId' => $shardId,
'StreamName' => $streamName,
'ShardIteratorType' => 'AT_TIMESTAMP',
'Timestamp' => $from_timestamp, //PROBLEM HERE
];
// this gets stuck (without timeout)
$res = $kinesisClient->getShardIterator($getShardItParams);

AWS S3 authorization mechanism - Signature 4

I'm currently struggling with getting a S3 download link working. I've been using this code as reference but when I try to open the file, I get the error:
The authorization mechanism you have provided is not supported. Please
use AWS4-HMAC-SHA256.
I tried a few other scripts floating around, but all ended with some other error message.
Is there an easy way to migrate the script I'm using to make it work with Signature v4?
UPDATE: as suggested by hjpotter92, I used the AWS-SDK and came up with this working code:
$client = S3Client::factory([
'version' => 'latest',
'region' => 'eu-central-1',
'signature' => 'v4',
'credentials' => [
'key' => '12345',
'secret' => 'ABCDE'
]
]);
$cmd = $client->getCommand('GetObject', [
'Bucket' => '###name###',
'Key' => $fileName
]);
$request = $client->createPresignedRequest($cmd, '+2 minutes');
$presignedUrl = (string) $request->getUri();
return $presignedUrl;

The SenderID and SMSType is taking default one in AWS SNS sdk for PHP

I am using AWS SDK for PHP.
I am trying to send messages to numbers. Which is working for few numbers and will not work if DND is activated for South-east.
I tried both the Transactional and Promotional but which is not working for DND activated numbers. The senderID and smsType didn't change.
Which is taking the default one even though I mentioned the smsType and senderID.
Here is the link which I used to implement. I googled for samples. I didn't get any proper documentation for SNS using PHP.
I found an answer for my question. I am posting this code believing that it would help some one in need.
I was doing wrong in while passing the senderID and SMSType.
require './vendor/autoload.php';
use Aws\Sns\SnsClient;
$client = new SnsClient(['region' => 'ap-southeast-1', 'version' => 'latest',
'credentials' => ['key' => 'XXXXXXXXXXX', 'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXX']]);
$result = $client->publish(array('Message' => $message_mobile, 'PhoneNumber' => $mobile_no,
'MessageAttributes' => array('AWS.SNS.SMS.SMSType' => array('StringValue' => 'Transactional', 'DataType' => 'String'),
'AWS.SNS.SMS.SenderID' => array('StringValue' => 'LIMAHB', 'DataType' => 'String'))));

AWS PHP SDK Version 2 S3 putObject Error

So the AWS php sdk 2.x library has been put out recently and I've taken a turkey day plunge into upgrading from 1.5x. My first was to upgrade my S3 backup class. I've quickly run into an error:
Fatal error: Class 'EntityBody' not found in /usr/share/php/....my file here
when trying to upload a zipped file to an S3 bucket. I wrote a class to abstract the writing a bit to allow for multi-region backup, so the code below references to $this are that.
$response1 = $s3->create_object(
$this->bucket_standard,
$this->filename,
array(
'fileUpload' => $this->filename,
'encryption' => 'AES256',
//'acl' => AmazonS3::ACL_PRIVATE,
'contentType' => 'text/plain',
'storage' => AmazonS3::STORAGE_REDUCED,
'headers' => array( // raw headers
'Cache-Control' => 'max-age',
//'Content-Encoding' => 'gzip',
'Content-Language' => 'en-US'
//'Expires' => 'Thu, 01 Nov 2012 16:00:00 GMT'
),
'meta' => array(
'param1' => $this->backupDateTime->format('Y-m-d H:i:s'), // put some info on the file in meta tags
'param2' => $this->hostOrigin
)
)
);
The above worked fine on 1.5.x.
Now, in 2.x, I'm looking into their docs and they've changed just about everything (great...maximum sarcasm)
$s3opts=array('key'=> $this->accessKey, 'secret' => $this->secretKey,'region' => 'us-east-1');
$s3 = Aws\S3\S3Client::factory($s3opts);
so now I've got a new S3 object. And here is my 2.x syntax to do the same exact thing. My problem arises where they've (sinisterly) changed the old "fileupload" to "Body" and made it more abstract in how to actually attach a file! I've tried both and I'm thinking it has to do with the dependencies (Guzzle or Smyfony etc), but I get the error above (or substitute Stream if you like) whenever I try to execute this.
I've tried using Composer with composer.json, and the aws.phar but before I get into that, is there something dumb I'm missing?
$response1 = $s3->putObject(array(
'Bucket' => $this->bucket_standard,
'Key' => $this->filename,
'ServerSideEncryption' => 'AES256',
'StorageClass' => 'REDUCED_REDUNDANCY',
'Body' => EntityBody::factory(fopen($this->filename, 'r')),
//'Body' => new Stream(fopen($fullPath, 'r')),
'MetaData' => array(
'BackupTime' => $this->backupDateTime->format('Y-m-d H:i:s'), // put some info on the file in meta tags
'HostOrigin' => $this->hostOrigin
)
));
Thanks as always,
R
Did you import the EntityBody into your namespace?
use Guzzle\Http\EntityBody;
Otherwise, you'd have to do
'Body' => \Guzzle\Http\EntityBody::factory(fopen($this->filename, 'r')),

Categories