How to create Athena View using CDK
I want to use this CREATE VIEW option in the Athena console to run a query which will create a View in the Glue Database. But I want to use CDK. My question is : What’s the easiest way to create an Athena View using monocdk, which will create a view in the Glue DataBase?
Seeing that creating CfnNamedQuery construct with the 'CREATE OR REPLACE VIEW' query will just create a Saved Query. So I’ll have to run it once via the console to actually create the view, which defeats the purpose. I’m fairly new to Athena and CDK, so would be great help if anyone can point me towards the right direction. Thanks!
(PS : Markdown for the embedding the picture doesn't seem to be working. The picture is a screenshot of the Athena console : https://tiny.amazon.com/1dzv084cv/drivcorpamazviewananpublScre)
Views are tables with some additional properties on glue catalog.
So, you can create a glue table informing the properties: view_expanded_text
and view_original_text
. This tables will be executed as a view on Athena.
More details on https://docs.aws.amazon.com/cdk/api/v1/python/aws_cdk.aws_glue/CfnTable.html#tableinputproperty
Thanks for this! One concern : I want to create the view from an existing CDK generated glue table(which is populated by a Glue Crawler). Let's say I add a column to the source glue table(ie, its schema changes), can there be a stale view issue(since I read that glue tables are created parallely). What sort of 'stale view' cases like this should I look out for?
Relevant questions
Simple query runs so long
asked 5 hours agoSave / backup Athena view
Accepted Answerasked 2 years agoIs AthenaDynamoDBConnector available for CDK
asked 2 months agoAccessing Amazon Athena over JDBC with an IAM role
Accepted Answerasked 2 years agoCreate a Glue table (Presto/Athena view) for analyzing ALB logs using CloudFormation or Terraform
asked 5 months agoS3 Select vs Athena
Accepted Answerasked 2 years agoUsing Cloud Trail Console to view all events in multi-account CloudTrail ( created via Organizations )
Accepted Answerasked 15 days agoWhat permissions configurations are required on an S3 bucket for Athena to be able to Preview View on an object?
asked 2 months agoHow to create Athena View using CDK
Accepted Answerasked 4 months agoCan we add column to an existing table in AWS Athena using SQL query?
Accepted Answerasked 3 years ago
Please not that the text to be used in the 2 parameter needs to follow some rule, for example view_original_text must contain an encoded Presto view , you can look at this stackoverflow answer for further information https://stackoverflow.com/questions/56289272/create-aws-athena-view-programmatically