1
votes

In the documentation for AWS::Athena::NamedQuery we have a lovely YAML,

Resources:
  AthenaNamedQuery:
    Type: AWS::Athena::NamedQuery
    Properties:
      Database: "swfnetadata"
      Description: "A query that selects all aggregated data"
      Name: "MostExpensiveWorkflow"
      QueryString: >
                    SELECT workflowname, AVG(activitytaskstarted) AS AverageWorkflow
                    FROM swfmetadata
                    WHERE year='17' AND GROUP BY workflowname
                    ORDER BY AverageWorkflow DESC LIMIT 10

But what is Database: "swfnetadata"? Where/how do I define that?

2

2 Answers

2
votes

AWS Athena tables can only exist within databases.

From the docs:

Athena uses Apache Hive to define tables and create databases, which are essentially a logical namespace of tables. When you create a database and table in Athena, you are simply describing the schema and where the table data are located in Amazon S3 for read-time querying.

So in your case, you have to state the database where the table was created in.

Creating Databases and Tables

1
votes

Cloudformation snippet to create an Athena database, which is a Glue database.

Parameters:
  DatabaseName:
    Type: String
    Default: dev_db
Resources:
 # Create an AWS Glue database
  MyDevAthenaDatabase:
    Type: AWS::Glue::Database
    Properties:
      # The database is created in the Data Catalog for your account
      CatalogId: !Ref AWS::AccountId
      DatabaseInput:
        # The name of the database is defined in the Parameters section above
        Name: !Ref DatabaseName
        Description: Database to hold dev tables
# Create tables
  MyGlueTable1:
    Type: AWS::Glue::Table
    DependsOn: MyDevAthenaDatabase