我可以使用带有startQueryExecution()的Athena API在S3中创建响应的CSV文件。但是,我希望能够向我的应用程序返回一个JSON响应,这样我就可以进一步处理数据。我试图在通过API运行startQueryExecution()后返回JSON结果,如何才能以JSON响应的形式返回结果?
我使用的是AWS PHP SDK [https://aws.amazon.com/sdk-for-php/],但是这与任何语言都相关,因为我无法找到任何实际返回响应的答案,它只是将一个CSV文件保存到S3。
$athena = AWS::createClient('athena');
$queryx = 'SELECT * FROM elb_logs LIMIT 20';
$result = $athena->startQueryExecution([
'QueryExecutionContext' => [
'Database' => 'sampledb',
],
'QueryString' => 'SELECT request_ip FROM elb_logs LIMIT 20', // REQUIRED
'ResultConfiguration' => [ // REQUIRED
'EncryptionConfiguration' => [
'EncryptionOption' => 'SSE_S3' // REQUIRED
],
'OutputLocation' => 's3://xxxxxx/', // REQUIRED
],
]);
// check completion : getQueryExecution()
$exId = $result['QueryExecutionId'];
sleep(6);
$checkExecution = $athena->getQueryExecution([
'QueryExecutionId' => $exId, // REQUIRED
]);
if($checkExecution["QueryExecution"]["Status"]["State"] == 'SUCCEEDED')
{
$dataOutput = $athena->getQueryResults([
'QueryExecutionId' => $result['QueryExecutionId'], // REQUIRED
]);
while (($data = fgetcsv($dataOutput, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
}https://stackoverflow.com/questions/47568281
复制相似问题