Skip to content

Commit c2bd35b

Browse files
author
Mark Ellens
committed
add data science policy
1 parent eb25b3f commit c2bd35b

File tree

4 files changed

+70
-453
lines changed

4 files changed

+70
-453
lines changed

terraform/iam_sagemaker.tf

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
resource "aws_iam_role_policy_attachment" "data_scientist_attach" {
2+
role = "switch-role-custom"
3+
policy_arn = "arn:aws:iam::aws:policy/job-function/DataScientist"
4+
}
5+
16
resource "aws_iam_role" "sm_notebook_instance_role" {
27
name = "sm-notebook-instance-role"
38

@@ -87,6 +92,20 @@ resource "aws_iam_policy" "sm_notebook_instance_policy" {
8792
"ec2:DescribeRouteTables"
8893
],
8994
"Resource": "*"
95+
},
96+
{
97+
"Sid": "EnforceInstanceType",
98+
"Effect": "Allow",
99+
"Action": [
100+
"sagemaker:CreateTrainingJob",
101+
"sagemaker:CreateHyperParameterTuningJob"
102+
],
103+
"Resource": "*",
104+
"Condition": {
105+
"ForAllValues:StringLike": {
106+
"sagemaker:InstanceTypes": ["ml.t2.large"]
107+
}
108+
}
90109
},
91110
{
92111
"Effect": "Allow",

terraform/outputs.tf

-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,3 @@ output "basic_notebook_instance_id" {
22
value = "${aws_sagemaker_notebook_instance.basic.id}"
33
}
44

5-
output "firehose_delivery_stream_arn" {
6-
description = "Firehose Delivery Stream ARN"
7-
value = "${aws_kinesis_firehose_delivery_stream.fraud_detection_firehose_stream.arn}"
8-
}
9-
10-
output "firehoseDeliveryRoleArn" {
11-
description = "Firehose Delivery Role ARN"
12-
value = "${aws_iam_role.fraud_detection_firehose_role.arn}"
13-
}

terraform/s3_function.tf

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
resource "aws_s3_bucket" "fraud_detection_function_bucket" {
2+
bucket = "${var.function_bucket_name}-${var.aws_region}"
3+
acl = "private"
4+
5+
server_side_encryption_configuration {
6+
rule {
7+
apply_server_side_encryption_by_default {
8+
sse_algorithm = "AES256"
9+
}
10+
}
11+
}
12+
13+
tags = {
14+
Description = "Bucket hosting the code for fraud_detection Lambda function."
15+
Group = var.default_resource_group
16+
CreatedBy = var.default_created_by
17+
}
18+
}
19+
20+
data "archive_file" "fraud_detection_archive" {
21+
type = "zip"
22+
source_file = "${path.module}/../source/fraud_detection/index.py"
23+
output_path = "${path.module}/../dist/fraud_detection.zip"
24+
}
25+
26+
resource "aws_s3_bucket_object" "s3_fraud_detection_archive" {
27+
bucket = aws_s3_bucket.fraud_detection_function_bucket.id
28+
key = "fraud-detection-using-machine-learning/${var.function_version}/fraud_detection.zip"
29+
source = data.archive_file.fraud_detection_archive.output_path
30+
31+
# The filemd5() function is available in Terraform 0.11.12 and later
32+
# For Terraform 0.11.11 and earlier, use the md5() function and the file() function:
33+
# etag = "${md5(file("path/to/file"))}"
34+
etag = filemd5(data.archive_file.fraud_detection_archive.output_path) # use md5 of index.py to detect changes in the function
35+
}

0 commit comments

Comments
 (0)