Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_session():
session = awswrangler.common.get_session()
session.client("sts").get_caller_identity().get("Account")
profile = session.profile_name
key = session.get_credentials().access_key
secret = session.get_credentials().secret_key
region = session.region_name
session = awswrangler.common.get_session(profile=profile)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(region=region)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(key=key, secret=secret)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives()
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives(profile=profile)
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives(region=region)
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(key=key, secret=secret)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives()
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives(profile=profile)
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives(region=region)
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives(key=key, secret=secret)
)
session.client("sts").get_caller_identity().get("Account")
def test_get_session():
session = awswrangler.common.get_session()
session.client("sts").get_caller_identity().get("Account")
profile = session.profile_name
key = session.get_credentials().access_key
secret = session.get_credentials().secret_key
region = session.region_name
session = awswrangler.common.get_session(profile=profile)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(region=region)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(key=key, secret=secret)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives()
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
def test_get_session():
session = awswrangler.common.get_session()
session.client("sts").get_caller_identity().get("Account")
profile = session.profile_name
key = session.get_credentials().access_key
secret = session.get_credentials().secret_key
region = session.region_name
session = awswrangler.common.get_session(profile=profile)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(region=region)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(key=key, secret=secret)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives()
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives(profile=profile)
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives(region=region)
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
def test_get_session():
session = awswrangler.common.get_session()
session.client("sts").get_caller_identity().get("Account")
profile = session.profile_name
key = session.get_credentials().access_key
secret = session.get_credentials().secret_key
region = session.region_name
session = awswrangler.common.get_session(profile=profile)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(region=region)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(key=key, secret=secret)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives()
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives(profile=profile)
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives(region=region)
)
session.client("sts").get_caller_identity().get("Account")
session = awswrangler.common.get_session(
session_primitives=awswrangler.common.SessionPrimitives(key=key, secret=secret)
)
def table_exists(database, table, session_primitives=None):
"""
Check if a specific Glue table exists
"""
client = get_session(session_primitives=session_primitives).client("glue")
try:
client.get_table(DatabaseName=database, Name=table)
return True
except client.exceptions.EntityNotFoundException:
return False
def add_partitions(
database, table, partition_paths, file_format, session_primitives=None
):
"""
Add a list of partitions in a Glue table
"""
client = get_session(session_primitives=session_primitives).client("glue")
if not partition_paths:
return None
partitions = list()
for partition in partition_paths:
if file_format == "parquet":
partition_def = p_get_partition_definition(partition)
elif file_format == "csv":
partition_def = c_get_partition_definition(partition)
else:
raise UnsupportedFileFormat(file_format)
partitions.append(partition_def)
pages_num = int(ceil(len(partitions) / 100.0))
for _ in range(pages_num):
page = partitions[:100]
del partitions[:100]
client.batch_create_partition(
def get_connection_details(name, session_primitives=None):
client = get_session(session_primitives=session_primitives).client("glue")
return client.get_connection(Name=name, HidePassword=False)["Connection"]
def create_table(
database,
table,
schema,
path,
file_format,
partition_cols=None,
session_primitives=None,
):
"""
Create Glue table
"""
client = get_session(session_primitives=session_primitives).client("glue")
if file_format == "parquet":
table_input = p_get_table_definition(table, partition_cols, schema, path)
elif file_format == "csv":
table_input = c_get_table_definition(table, partition_cols, schema, path)
else:
raise UnsupportedFileFormat(file_format)
client.create_table(DatabaseName=database, TableInput=table_input)
def read(
database, query, s3_output=None, region=None, key=None, secret=None, profile=None
):
"""
Read any Glue object through the AWS Athena
"""
session = get_session(key=key, secret=secret, profile=profile, region=region)
if not s3_output:
account_id = session.client("sts").get_caller_identity().get("Account")
session_region = session.region_name
s3_output = (
"s3://aws-athena-query-results-" + account_id + "-" + session_region + "/"
)
s3 = session.resource("s3")
s3.Bucket(s3_output)
athena_client = session.client("athena")
qe = run_query(athena_client, query, database, s3_output)
validation = query_validation(athena_client, qe)
if validation.get("QueryExecution").get("Status").get("State") == "FAILED":
message_error = "Your query is not valid: " + validation.get(
"QueryExecution"
).get("Status").get("StateChangeReason")
raise Exception(message_error)