This repository was archived by the owner on Jan 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup_lab.py
More file actions
executable file
·78 lines (63 loc) · 2.24 KB
/
setup_lab.py
File metadata and controls
executable file
·78 lines (63 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import boto3
import botocore
import os
def color(text: str, color: str = "cyan") -> str:
"""
colors the output to terminal -- nicer aesthetic!
"""
if color == "cyan":
r, g, b = 0, 255, 255
elif color == "orange":
r, g, b = 255, 179, 71
elif color == "green":
r, g, b = 57, 255, 20
return f"\033[38;2;{r};{g};{b}m{text}\033[38;2;255;255;255m"
bucket_name_parameter = "MacieDevlabBucketName"
sensitive_data_folder = "test-data"
ssm_client = boto3.client("ssm")
s3_client = boto3.client("s3")
macie_client = boto3.client("macie2")
bucket_name = ssm_client.get_parameter(Name=bucket_name_parameter)["Parameter"]["Value"]
bucket_location = s3_client.get_bucket_location(Bucket=bucket_name)[
"LocationConstraint"
]
if bucket_location is None:
bucket_location = "us-east-1"
print(
f"Bucket with test data is {color(bucket_name)} in the {color(bucket_location,color='orange')} region"
)
macie_console_link = f"https://{bucket_location}.console.aws.amazon.com/macie/home?region={bucket_location}"
list_files = os.listdir(sensitive_data_folder)
for file_name in list_files:
response = s3_client.upload_file(
f"./{sensitive_data_folder}/{file_name}", bucket_name, file_name
)
print(f"Uploaded test data to {color(bucket_name)} bucket")
try:
macie_client.disable_macie()
print("Disabled installation of Macie from previous Lab Participant")
except macie_client.exceptions.from_code("AccessDeniedException") as e:
print(e.response["Error"]["Message"])
macie_client.enable_macie()
response = macie_client.get_macie_session()
macie_client.create_custom_data_identifier(
description="Passport number of Gotham Citizens",
keywords=[
"passport",
],
maximumMatchDistance=50,
name="Gotham Passport",
regex="[ABCDEF]\\d{7}[A-Z]",
severityLevels=[
{"occurrencesThreshold": 1, "severity": "HIGH"},
],
)
if response["status"] == "ENABLED":
print("Macie enabled!\n\n")
print(f"🚀 {color('You are ready to go',color='green')} 🚀")
print(
f"Click this link, and then click open to continue to Macie: {color(macie_console_link, color='cyan')}"
)
print("\n\n")
else:
print("Error enabling Macie, please check with the lab organizer")