๋ชฉ์ฐจ
์ ๊ธฐ
์๋ ํ์ธ์ ๐ค
์ค๋์ ๋ฌธ์๊ฐ ๋ง์ง ์์์ ์ ๋ฅผ ๋จน์.... php sdk๋ฅผ ์ด์ฉํ Athena ์ฟผ๋ฆฌ ์ ๋๋ค!!!
- AWS SDK for PHP 3 ์ค์น : https://docs.aws.amazon.com/ko_kr/sdk-for-php/v3/developer-guide/getting-started_installation.html
- AWS SDK ๋ฌธ์ : https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.Athena.AthenaClient.html
- ์ํ์ฝ๋
<?php
/*---------------------------
* AWS SDK ๋ก๋ & ํด๋ผ์ด์ธํธ ์ธ์คํด์ค ์์ฑ
----------------------------- */
require './vendor/autoload.php';
$options = [
'region' => 'ap-northeast-2',
'version' => 'latest',
];
$athenaClient = new Aws\Athena\AthenaClient($options);
/*---------------------------
* SQL ์คํ
----------------------------- */
$result = $athenaClient->startQueryExecution([
'QueryExecutionContext' => [
'Database' => 'default', //athena ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ด๋ฆ ์ฐ์ธ์!
],
'QueryString' => 'select * from cloudfront_logs limit 10', //์ฌ๊ธฐ์ ์ฟผ๋ฆฌ ์ฐ์ธ์!
'ResultConfiguration' => [
'OutputLocation' => 's3://athena-sdk-result/' , //๊ฒฐ๊ณผ ์ ์ฅ๋ S3 ๊ฒฝ๋ก ์ฐ์ธ์!
],
'WorkGroup' => 'primary', // ์ํฌ๊ทธ๋ฃน ์ฐ์ธ์!!
]);
$result_QueryExecutionId = $result['QueryExecutionId'];
/*---------------------------
* While ๋ฃจํ๋๋ฉด์ SQL ์ฟผ๋ฆฌ ์ํ ํ์ธ
----------------------------- */
$stat_flg = true;
while ($stat_flg){
$result = $athenaClient->getQueryExecution([
'QueryExecutionId' => $result_QueryExecutionId
]);
// Debug
echo "Query status = ".$result['QueryExecution']['Status']['State'] ."\n";
if ($result['QueryExecution']['Status']['State'] == 'SUCCEEDED'){
$stat_flg = false;
}
}
/*---------------------------
* SQL ๊ฒฐ๊ณผ ํ์ธ
----------------------------- */
$result = $athenaClient->getQueryResults([
'QueryExecutionId' => $result_QueryExecutionId
]);
print ($result);
?>
728x90