agent: |
QihhZKCozaisYMq4aa9FConfigure AWS Cost And Usage Report to a S3 Bucket
Configure AWS Cost And Usage Report to a S3 Bucket
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
This task involves configuring AWS Cost and Usage Reports (CUR) to direct the reports to the newly created and configured S3 bucket, finalizing the setup for report generation and storage.
inputs
outputs
import boto3
from botocore.exceptions import ClientError
# Retrieve AWS credentials from the vault
creds = _get_creds(cred_label)['creds']
access_key = creds['username']
secret_key = creds['password']
def configure_cur_report(bucket_name, report_name, region_name):
"""
Configures AWS Cost and Usage Report to be delivered to an S3 bucket with Parquet format for Athena.
:param bucket_name: Name of the S3 bucket for report delivery.
:param report_name: Name of the report.
:param region_name: AWS region where the S3 bucket is located.
"""
cur_client = boto3.client('cur', aws_access_key_id=access_key, aws_secret_access_key=secret_key, region_name='us-east-1')
report_definition = {
'ReportName': report_name,
'TimeUnit': 'HOURLY',
'Format': 'Parquet',
'Compression': 'Parquet',
'S3Bucket': bucket_name,
'S3Prefix': f"{report_name}/{report_name}/date-range/",
'S3Region': region_name,
'AdditionalSchemaElements': ['RESOURCES'],
'ReportVersioning': 'OVERWRITE_REPORT', # Updated to OVERWRITE_REPORT
'AdditionalArtifacts': ['ATHENA'], # Enable integration for Athena
'RefreshClosedReports': True
}
try:
response = cur_client.put_report_definition(ReportDefinition=report_definition)
print(f"CUR report '{report_name}' configured for delivery to '{bucket_name}'.")
except ClientError as e:
print(f"Error configuring CUR report: {e}")
# Example usage
#bucket_name = 'dagknows-cur-logging-bucket-athena-test-188379622596'
#report_name = 'My-CUR-report-Athena-Test-1234'
#region_name = 'us-east-1' # Replace with your region, e.g., 'us-east-1'
configure_cur_report(BUCKET_NAME, report_name, region_name)
copied