Athena : no viable alternative at input for 'create external table' in python

370 Views Asked by At

I am trying to create an Athena table for s3 server access logs in my python cdk code with the help of this AWS link: https://aws.amazon.com/premiumsupport/knowledge-center/analyze-logs-athena/

The table gets created successfully from the Athena console but gives a - no viable alternative at input "CREATE EXTERNAL" error while I try to do the same using the Python code.

I am not able to figure out the problem here This is my python code:

query_string="""CREATE EXTERNAL TABLE IF NOT EXISTS bucket_logs_db.access_logs(
                                            BucketOwner STRING,
                                            Bucket STRING,
                                            RequestDateTime STRING,
                                            RemoteIP STRING,
                                            Requester STRING,
                                            RequestID STRING,
                                            Operation STRING,
                                            Key STRING,
                                            RequestURI_operation STRING,
                                            RequestURI_key STRING,
                                            RequestURI_httpProtoversion STRING,
                                            HTTPstatus STRING,
                                            ErrorCode STRING,
                                            BytesSent BIGINT,
                                            ObjectSize BIGINT,
                                            TotalTime STRING,
                                            TurnAroundTime STRING,
                                            Referrer STRING,
                                            UserAgent STRING,
                                            VersionId STRING,
                                            HostId STRING,
                                            SigV STRING,
                                            CipherSuite STRING,
                                            AuthType STRING,
                                            EndPoint STRING,
                                            TLSVersion STRING
                                        )
                                        ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'
                                        WITH SERDEPROPERTIES (
                                                 'serialization.format' = '1', 'input.regex' = '([^ ]*) ([^ ]*) \\[(.*?)\\]
                                                 ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) \\\"([^ ]*) ([^ ]*) (- |[^ ]*)\\\"
                                                 (-|[0-9]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) (\"[^\"]*\")
                                                 ([^ ]*)(?: ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*))?.*$' )
                                        LOCATION 's3://' + f'{bucket.bucket_name}' + /prefix'"""
0

There are 0 best solutions below