# import sys
# from awsglue.utils import getResolvedOptions
# from awsglue.context import GlueContext
# from pyspark.context import SparkContext
# from awsglue.job import Job
# import boto3

# # ------------------------------
# # Job Initialization
# # ------------------------------
# args = getResolvedOptions(sys.argv, ['JOB_NAME'])

# # Safe SparkContext initialization
# sc = SparkContext.getOrCreate()
# glueContext = GlueContext(sc)
# spark = glueContext.spark_session
# logger = glueContext.get_logger()
# job = Job(glueContext)
# job.init(args['JOB_NAME'], args)

# # ------------------------------
# # Configuration
# # ------------------------------
# source_database = "rds_postgres_db"
# target_connection = "Jdbc-connection-redshift"
# target_database = "dev"
# temp_dir = "s3://aws-glue-assets-896271372615-ap-south-1/temporary/"

# # Create a Glue client (region inferred from job role)
# glue_client = boto3.client('glue', region_name='ap-south-1')

# # Pull the table list from the Glue Data Catalog
# tables = glue_client.get_tables(DatabaseName=source_database)['TableList']

# # ------------------------------
# # Sync loop
# # ------------------------------
# for t in tables:
#     table_name = t['Name']
#     logger.info(f":arrows_counterclockwise: Syncing table: {table_name}")
#     try:
#         # Read table from PostgreSQL
#         datasource = glueContext.create_dynamic_frame.from_catalog(
#             database=source_database,
#             table_name=table_name
#         )

#         # Write table to Redshift
#         glueContext.write_dynamic_frame.from_jdbc_conf(
#             frame=datasource,
#             catalog_connection=target_connection,
#             connection_options={
#                 "dbtable": table_name,
#                 "database": target_database,
#                 "preactions": f"TRUNCATE TABLE {table_name}"  # safer than 'overwrite'
#             },
#             redshift_tmp_dir=temp_dir
#         )
#         logger.info(f":white_check_mark: Successfully synced table: {table_name}")
#     except Exception as e:
#         logger.error(f":warning: Failed to sync {table_name}: {str(e)}")
#         continue  # continue with the next table

# # ------------------------------
# # Commit job
# # ------------------------------
# job.commit()
# logger.info(":tada: Glue job finished successfully!")

import boto3
s3 = boto3.client('s3')
print(s3.list_buckets())