

# Setting up Athena using Amazon CloudFormation templates
<a name="use-athena-cf"></a>

**Important**  
Amazon CloudFormation doesn't support cross-Region resources. If you plan to use an Amazon CloudFormation template, you must create all resources in the same Amazon Region. The Region must support the following services:  
Amazon Lambda
Amazon Simple Storage Service (Amazon S3)
Amazon Glue
Amazon Athena

To streamline and automate integration of your Cost and Usage Reports with Athena, Amazon provides an Amazon CloudFormation template with several key resources along with the reports that you set up for Athena integration. The Amazon CloudFormation template includes an Amazon Glue crawler, an Amazon Glue database, and an Amazon Lambda event. 

The Athena integration setup process using Amazon CloudFormation removes any Amazon S3 events that your bucket might already have. This can negatively affect any existing event-based processes that you have for an existing Amazon CUR report. We strongly recommend that you create both a new Amazon S3 bucket and a new Amazon CUR report to use with Athena.

Before you can use a CloudFormation template to automate Athena integration, make sure that you do the following:
+ Create a new Amazon S3 bucket for your reports. For more information, see [Creating a bucket](https://docs.amazonaws.cn/AmazonS3/latest/userguide/create-bucket-overview.html) in the *Amazon S3 User Guide*. 
+ [Create a new report](cur-create.md) to use with Athena. During the setup process, for **Report data integration**, choose **Athena**.
+ Wait for the first report to be delivered to your Amazon S3 bucket. It can take up to 24 hours for Amazon to deliver your first report.<a name="use-athena-cf-steps"></a>

**To use the Athena Amazon CloudFormation template**

1. Open the Amazon S3 console at [https://console.amazonaws.cn/s3/](https://console.amazonaws.cn/s3/).

1. From the list of buckets, choose the bucket where you chose to receive your Amazon CUR report.

1. Choose your report path prefix (*your-report-path-prefix/*). Then, choose your report name (*your-report-name/*).

1. Choose the `.yml` template file.

1. Choose **Object actions**, and then choose **Download as**.

1. Open the Amazon CloudFormation console at [https://console.amazonaws.cn/cloudformation](https://console.amazonaws.cn/cloudformation/).

1. If you have never used Amazon CloudFormation before, choose **Create New Stack**. Otherwise, choose **Create Stack**.

1. Under **Prepare template**, choose **Template is ready**.

1. Under **Template source**, choose **Upload a template file**.

1. Choose **Choose file**.

1. Choose the downloaded `.yml` template, and then choose **Open**.

1. Choose **Next**.

1. For **Stack name**, enter a name for your template and choose **Next**.

1. Choose **Next**.

1. At the bottom of the page, select **I acknowledge that Amazon CloudFormation might create IAM resources.** 

   This template creates the following resources:
   + Three IAM roles
   + An Amazon Glue database
   + An Amazon Glue crawler
   + Two Lambda functions
   + An Amazon S3 notification

1. Choose **Create stack**.

**To update the existing Athena Amazon CloudFormation template**

1. Open the Amazon S3 console at [https://console.amazonaws.cn/s3/](https://console.amazonaws.cn/s3/).

1. From the list of buckets, choose the bucket where you chose to receive your Amazon CUR report.

1. Choose your report path prefix (*your-report-path-prefix/*). Then, choose your report name (*your-report-name/*).

1. Choose the `.yml` template file.

1. Choose **Object actions**, and then choose **Download as**.

1. Open the Amazon CloudFormation console at [https://console.amazonaws.cn/cloudformation](https://console.amazonaws.cn/cloudformation/).

1. Select the stack that was previously created, and then choose **Update**.

1. Under **Prepare template**, choose **Replace current template**.

1. Under **Template source**, choose **Upload a template file**.

1. Choose **Choose file**.

1. Choose the downloaded `.yml` template, and then choose **Open**.

1. Choose **Next**.

1. On the **Specify stack details** page, modify any details, and then choose **Next**.

1. Choose **Next**.

1. At the bottom of the page, select **I acknowledge that Amazon CloudFormation might create IAM resources.** 

1. Choose **Update stack**.