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.
Parameters
-
database
required - string -
description
optional - string -
id
optional computed - string -
name
required - string -
query
required - string -
workgroup
optional - string
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.
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.
aws_athena_workgroup
Enable Athena workgroup configuration enforcement
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
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
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
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
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
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
"Type": "AWS::Athena::NamedQuery",
"DependsOn": ["S3Bucket"],
"Properties": {
"Database": "default",
"Name": "CreateUsersTable",
"Description": "Create a Users Table",
"Type" : "AWS::Athena::NamedQuery",
"Properties" : {
"Description" : "{{settings["description"]}}",
"QueryString" : "{{settings["querystring"]}}",
"Database" : "{{settings["database"]}}",
"Name" : "{{settings["name"]}}"
"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",
"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",
"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
-
Name
optional - String -
Database
required - String -
Description
optional - String -
QueryString
required - String -
WorkGroup
optional - String
Explanation in CloudFormation Registry
The
AWS::Athena::NamedQuery
resource specifies an Amazon Athena saved query, whereQueryString
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.