LoginSignup
1
0

More than 5 years have passed since last update.

AthenaのAPI操作をIAMで制御

Last updated at Posted at 2017-07-08

Athena のAPIは今のところこれ

pioho $ aws athena help
:
AVAILABLE COMMANDS
       o batch-get-named-query

       o batch-get-query-execution

       o create-named-query

       o delete-named-query

       o get-named-query

       o get-query-execution

       o get-query-results

       o help

       o list-named-queries

       o list-query-executions

       o start-query-execution

       o stop-query-execution

クエリ実行して、クエリの状態見て、結果を得る

start-query-execution

※ちなみにOutputLocationでクエリ結果がS3に出力されますが、これ必須です。つけないとエラーです。今のところそういった仕様です。

pioho $ aws athena start-query-execution --query-string "select * from sampledb.elb_logs limit 10" --result-configuration OutputLocation=s3://aws-athena-query-results
{
    "QueryExecutionId": "0ec3a09e-144b-4a6c-b2f4-a2fb790e4141"
}

get-query-execution

pioho $ aws athena get-query-execution --query-execution-id 0ec3a09e-144b-4a6c-b2f4-a2fb790e4141
{
    "QueryExecution": {
        "Status": {
            "SubmissionDateTime": 1499483900.008, 
            "State": "SUCCEEDED", 
            "CompletionDateTime": 1499483901.083
        }, 
        "Query": "select * from sampledb.elb_logs limit 10", 
        "Statistics": {
            "DataScannedInBytes": 282613, 
            "EngineExecutionTimeInMillis": 956
        }, 
        "ResultConfiguration": {
            "OutputLocation": "s3://aws-athena-query-results/0ec3a09e-144b-4a6c-b2f4-a2fb790e4141.csv"
        }, 
        "QueryExecutionId": "0ec3a09e-144b-4a6c-b2f4-a2fb790e4141"
    }
}

get-query-results

pioho $ aws athena get-query-results --query-execution-id 0ec3a09e-144b-4a6c-b2f4-a2fb790e4141
{
    "ResultSet": {
        "Rows": [
            {
                "Data": [
                    {
                        "VarCharValue": "request_timestamp"
                    }, 
                    {
                        "VarCharValue": "elb_name"
                    }, 
                    {
                        "VarCharValue": "request_ip"
                    }, 
                    {
                        "VarCharValue": "request_port"
                    }, 
                    {
                        "Var
:
:
:

getresultを拒否する

IAM ポリシーをDenyで作成し適用(画像は許可だど..)

スクリーンショット 0029-07-08 11.35.45.png

Deny get-query-results

pioho $ aws athena get-query-results --query-execution-id 0ec3a09e-144b-4a6c-b2f4-a2fb790e4141
An error occurred (AccessDeniedException) when calling the GetQueryResults operation: User: arn:aws:iam::xxxxxxx:user/piko is not authorized to perform: athena:GetQueryResults

AWS Organization

こちらでも制御できるのでAthenaだけ実行させたいアカウントとかもいいかもね

スクリーンショット 0029-07-08 13.18.29.png

あとは

リソースをもう少し細かく制御できるといいなぁと

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0