-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_aws_infrastructure.sh
More file actions
76 lines (66 loc) · 1.93 KB
/
setup_aws_infrastructure.sh
File metadata and controls
76 lines (66 loc) · 1.93 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
#!/bin/bash
# Set variables
AWS_REGION="ap-southeast-1"
BUCKET_NAME="brain-ct-async-inference-krooldonutz"
SUCCESS_TOPIC_NAME="brain-ct-success-krooldonutz"
ERROR_TOPIC_NAME="brain-ct-error-krooldonutz"
TIMESTAMP="2025-04-27-0427"
# Create S3 bucket
echo "Creating S3 bucket..."
aws s3api create-bucket \
--bucket "$BUCKET_NAME" \
--region "$AWS_REGION" \
--create-bucket-configuration LocationConstraint="$AWS_REGION"
# Enable versioning on the bucket (recommended for production)
aws s3api put-bucket-versioning \
--bucket "$BUCKET_NAME" \
--versioning-configuration Status=Enabled
# Create SNS topics
echo "Creating SNS topics..."
SUCCESS_TOPIC_ARN=$(aws sns create-topic \
--name "$SUCCESS_TOPIC_NAME" \
--region "$AWS_REGION" \
--output text \
--query 'TopicArn')
ERROR_TOPIC_ARN=$(aws sns create-topic \
--name "$ERROR_TOPIC_NAME" \
--region "$AWS_REGION" \
--output text \
--query 'TopicArn')
# Output the ARNs
echo "Created resources:"
echo "S3 Bucket: $BUCKET_NAME"
echo "Success Topic ARN: $SUCCESS_TOPIC_ARN"
echo "Error Topic ARN: $ERROR_TOPIC_ARN"
# Create bucket policy
cat > bucket-policy.json << EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowSageMakerToWriteOutput",
"Effect": "Allow",
"Principal": {
"Service": "sagemaker.amazonaws.com"
},
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::${BUCKET_NAME}",
"arn:aws:s3:::${BUCKET_NAME}/*"
]
}
]
}
EOF
# Apply bucket policy
echo "Applying bucket policy..."
aws s3api put-bucket-policy \
--bucket "$BUCKET_NAME" \
--policy file://bucket-policy.json
# Clean up temporary files
rm bucket-policy.json
echo "Setup complete! Please update your Python code with these ARNs"