AWS Athena Named Query

This page shows how to write Terraform and CloudFormation for Athena Named Query and write them securely.

aws_athena_named_query (Terraform)

The Named Query in Athena can be configured in Terraform with the resource name aws_athena_named_query. The following sections describe how to use the resource and its parameters.

Example Usage from GitHub

An example could not be found in GitHub.

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides an Athena Named Query resource.

Tips: Best Practices for The Other AWS Athena Resources

In addition to the aws_athena_database, AWS Athena has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

aws_athena_database

Ensure to enable at rest encryption of Athena database

It is better to enable at rest encryption of Athena database. Encryption reduces the risk of data leakage.

risk-label

aws_athena_workgroup

Enable Athena workgroup configuration enforcement

Review your AWS Athena settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::Athena::NamedQuery (CloudFormation)

The NamedQuery in Athena can be configured in CloudFormation with the resource name AWS::Athena::NamedQuery. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

athena-sample-queries-appstream-usage-data_template.yml#L31
    Type: AWS::Athena::NamedQuery
    Properties:
      Database: appstream-usage
      Description: "Average AppStream 2.0 session length per stack in current month"
      Name: AS2_avg_session_length_curr_mo
      QueryString: "-- Average session length per stack for AppStream 2.0 user sessions launched during the current month
athena-sample-queries-appstream-usage-data_template.yml#L31
    Type: AWS::Athena::NamedQuery
    Properties:
      Database: appstream-usage
      Description: "Average AppStream 2.0 session length per stack in current month"
      Name: AS2_avg_session_length_curr_mo
      QueryString: "-- Average session length per stack for AppStream 2.0 user sessions launched during the current month
athena-sample-queries-appstream-usage-data_template.yml#L31
    Type: AWS::Athena::NamedQuery
    Properties:
      Database: appstream-usage
      Description: "Average AppStream 2.0 session length per stack in current month"
      Name: AS2_avg_session_length_curr_mo
      QueryString: "-- Average session length per stack for AppStream 2.0 user sessions launched during the current month
athena-sample-queries-appstream-usage-data_template.yml#L31
    Type: AWS::Athena::NamedQuery
    Properties:
      Database: appstream-usage
      Description: "Average AppStream 2.0 session length per stack in current month"
      Name: AS2_avg_session_length_curr_mo
      QueryString: "-- Average session length per stack for AppStream 2.0 user sessions launched during the current month
athena-sample-queries-appstream-usage-data_template.yml#L31
    Type: AWS::Athena::NamedQuery
    Properties:
      Database: appstream-usage
      Description: "Average AppStream 2.0 session length per stack in current month"
      Name: AS2_avg_session_length_curr_mo
      QueryString: "-- Average session length per stack for AppStream 2.0 user sessions launched during the current month
Template.json#L41
            "Type": "AWS::Athena::NamedQuery",
            "DependsOn": ["S3Bucket"],
            "Properties": {
                "Database": "default",
                "Name": "CreateUsersTable",
                "Description": "Create a Users Table",
athena_namedquery.json#L4
    "Type" : "AWS::Athena::NamedQuery",
    "Properties" : {
      "Description" : "{{settings["description"]}}",
      "QueryString" : "{{settings["querystring"]}}",
      "Database" : "{{settings["database"]}}",
      "Name" : "{{settings["name"]}}"
AthenaNamedQuerySpecification.json#L3
    "AWS::Athena::NamedQuery": {
      "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-athena-namedquery.html",
      "Properties": {
        "Description": {
          "Required": false,
          "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-athena-namedquery.html#cfn-athena-namedquery-description",
AthenaNamedQuerySpecification.json#L3
    "AWS::Athena::NamedQuery": {
      "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-athena-namedquery.html",
      "Properties": {
        "Description": {
          "Required": false,
          "Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-athena-namedquery.html#cfn-athena-namedquery-description",
AthenaTableWithGlueDataCatalog.json#L156
            "Type": "AWS::Athena::NamedQuery",
            "Properties": {
                "Description": "Query that lists recording file paths, starting from the most recent recording.",
                "QueryString": "SELECT filepath from recordingsearch<replace_with_path> ORDER BY startTime desc;",
                "Database": {
                    "Ref": "QueryDatabase"

Parameters

Explanation in CloudFormation Registry

The AWS::Athena::NamedQuery resource specifies an Amazon Athena saved query, where QueryString is the list of SQL query statements that comprise the query.

Frequently asked questions

What is AWS Athena Named Query?

AWS Athena Named Query is a resource for Athena of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Athena Named Query?

For CloudFormation, the lol-fi/finddiscount, Venkat1505/AWS-Doc-SDK-Examples and Shridharbhandar/AWS-CDK-DOC-Examples source code examples are useful. See the CloudFormation Example section for further details.