

# 使用 AWS CLI 生成 CloudFormation 模板
<a name="flow-logs-generate-template-cli"></a>

在将第一个流日志传送到 S3 存储桶后，您可以生成并使用 CloudFormation 模板与 Athena 集成。

使用下面的 [get-flow-logs-integration-template](https://docs.aws.amazon.com/cli/latest/reference/ec2/get-flow-logs-integration-template.html) 命令生成 CloudFormation 模板。

```
aws ec2 get-flow-logs-integration-template --cli-input-json file://config.json
```

以下是 `config.json` 文件的示例。

```
{
    "FlowLogId": "fl-12345678901234567",
    "ConfigDeliveryS3DestinationArn": "arn:aws:s3:::my-flow-logs-athena-integration/templates/",
    "IntegrateServices": {
        "AthenaIntegrations": [
            {
                "IntegrationResultS3DestinationArn": "arn:aws:s3:::my-flow-logs-analysis/athena-query-results/",
                "PartitionLoadFrequency": "monthly",
                "PartitionStartDate": "2021-01-01T00:00:00",
                "PartitionEndDate": "2021-12-31T00:00:00"
            }
        ]
    }
}
```

使用下面的 [create-stack](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-stack.html) 命令通过所生成的 CloudFormation 模板创建堆栈。

```
aws cloudformation create-stack --stack-name my-vpc-flow-logs --template-body file://my-cloudformation-template.json
```