Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating AWS Athena View using Cloud Formation template

Is it possible to create an Athena view via cloudformation template. I can create the view using the Athena Dashboard but I want to do this programmatically using CF templates. Could not find any details in AWS docs so not sure if supported.

Thanks.

like image 857
Infinite Avatar asked Sep 18 '25 03:09

Infinite


2 Answers

It is possible to create views with CloudFormation, it's just very, very, complicated. Athena views are stored in the Glue Data Catalog, like databases and tables are. In fact, Athena views are tables in Glue Data Catalog, just with slightly different contents.

See this answer for the full description how to create a view programmatically, and you'll get an idea for the complexity: Create AWS Athena view programmatically – it is possible to map that to CloudFormation, but I would not recommend it.

If you want to create databases and tables with CloudFormation, the resources are AWS::Glue::Database and AWS::Glue::Table.

like image 145
Theo Avatar answered Sep 19 '25 18:09

Theo


In general, CloudFormation is used for deploying infrastructure in a repeatable manner. This doesn't apply much to data inside a database, which typically persists separately to other infrastructure.

For Amazon Athena, AWS CloudFormation only supports:

  • Data Catalog
  • Named Query
  • Workgroup

The closest to your requirements is Named Query, which (I think) could store a query that can create the View (eg CREATE VIEW...).

See: AWS::Athena::NamedQuery - AWS CloudFormation

Update: @Theo points out that AWS CloudFormation also has AWS Glue functions that include:

  • AWS::Glue::Table

This can apparently be used to create a view. See comments below.

like image 38
John Rotenstein Avatar answered Sep 19 '25 20:09

John Rotenstein