Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions AWS_Glue_Crawler_and_Data_Catalog_with_Python/glue_crawler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import boto3
from botocore.exceptions import ClientError

## Change With Your Own Bucket
BUCKET_NAME = "glueworkshop-357171621133-us-west-2"
client = boto3.client('glue')

# Create database
# Create database
try:
response = client.create_database(
DatabaseInput={
Expand All @@ -13,10 +14,10 @@
}
)
print("Successfully created database")
except:
print("error in creating database")
except ClientError as e:
print(f"error in creating database: {e.response['Error']['Code']} - {e.response['Error']['Message']}")

# Create Glue Crawler
# Create Glue Crawler
try:
response = client.create_crawler(
Name='python-lab1',
Expand All @@ -25,24 +26,24 @@
Targets={
'S3Targets': [
{
'Path': 's3://{BUCKET_NAME}/input/lab1/csv'.format(BUCKET_NAME = BUCKET_NAME),
'Path': 's3://{BUCKET_NAME}/input/lab1/csv'.format(BUCKET_NAME=BUCKET_NAME),
},
{
'Path': 's3://{BUCKET_NAME}/input/lab5/json'.format(BUCKET_NAME = BUCKET_NAME),
'Path': 's3://{BUCKET_NAME}/input/lab5/json'.format(BUCKET_NAME=BUCKET_NAME),
}
]
},
TablePrefix='python_'
)
print("Successfully created crawler")
except:
print("error in creating crawler")
except ClientError as e:
print(f"error in creating crawler: {e.response['Error']['Code']} - {e.response['Error']['Message']}")

# This is the command to start the Crawler
try:
response = client.start_crawler(
Name='python-lab1'
)
print("Successfully started crawler")
except:
print("error in starting crawler")
except ClientError as e:
print(f"error in starting crawler: {e.response['Error']['Code']} - {e.response['Error']['Message']}")