Skip to content

Commit f4b2fe1

Browse files
committed
Seeding repo with 1.0.0-alpha8 of workshop code
1 parent 2de3429 commit f4b2fe1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+8798
-9
lines changed

.gitignore

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# System Files
2+
**/.DS_Store
3+
4+
# IDEs
5+
# JetBrains IDEs (Intellij, Pycharm etc.)
6+
.idea
7+
.idea/
8+
9+
# VSCode
10+
**/.vscode
11+
12+
# Byte-compiled / optimized / DLL files
13+
__pycache__/
14+
*.py[cod]
15+
*$py.class
16+
17+
# C extensions
18+
*.so
19+
20+
# Distribution / packaging
21+
.Python
22+
build/
23+
develop-eggs/
24+
dist/
25+
downloads/
26+
eggs/
27+
.eggs/
28+
lib/
29+
lib64/
30+
parts/
31+
sdist/
32+
var/
33+
wheels/
34+
pip-wheel-metadata/
35+
share/python-wheels/
36+
*.egg-info/
37+
.installed.cfg
38+
*.egg
39+
MANIFEST
40+
41+
# PyInstaller
42+
# Usually these files are written by a python script from a template
43+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
44+
*.manifest
45+
*.spec
46+
47+
# Installer logs
48+
pip-log.txt
49+
pip-delete-this-directory.txt
50+
51+
# Unit test / coverage reports
52+
htmlcov/
53+
.tox/
54+
.nox/
55+
.coverage
56+
.coverage.*
57+
.cache
58+
nosetests.xml
59+
coverage.xml
60+
*.cover
61+
*.py,cover
62+
.hypothesis/
63+
.pytest_cache/
64+
65+
# Translations
66+
*.mo
67+
*.pot
68+
69+
# Django stuff:
70+
*.log
71+
local_settings.py
72+
db.sqlite3
73+
db.sqlite3-journal
74+
75+
# Flask stuff:
76+
instance/
77+
.webassets-cache
78+
79+
# Scrapy stuff:
80+
.scrapy
81+
82+
# Sphinx documentation
83+
docs/_build/
84+
85+
# PyBuilder
86+
target/
87+
88+
# Jupyter Notebook
89+
.ipynb_checkpoints
90+
91+
# IPython
92+
profile_default/
93+
ipython_config.py
94+
95+
# pyenv
96+
.python-version
97+
98+
# pipenv
99+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
100+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
101+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
102+
# install all needed dependencies.
103+
#Pipfile.lock
104+
105+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
106+
__pypackages__/
107+
108+
# Celery stuff
109+
celerybeat-schedule
110+
celerybeat.pid
111+
112+
# SageMath parsed files
113+
*.sage.py
114+
115+
# Environments
116+
.env
117+
.venv
118+
env/
119+
venv/
120+
ENV/
121+
env.bak/
122+
venv.bak/
123+
124+
# Spyder project settings
125+
.spyderproject
126+
.spyproject
127+
128+
# Rope project settings
129+
.ropeproject
130+
131+
# mkdocs documentation
132+
/site
133+
134+
# mypy
135+
.mypy_cache/
136+
.dmypy.json
137+
dmypy.json
138+
139+
# Pyre type checker
140+
.pyre/
141+
142+
# CDK
143+
cdk.out/
144+
cdk.context.*

README.md

Lines changed: 467 additions & 9 deletions
Large diffs are not rendered by default.

buildspec.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: MIT-0
3+
version: 0.2
4+
5+
phases:
6+
pre_build:
7+
commands:
8+
- apt-get update
9+
- apt-get install python3-pip zip -y
10+
- pip3 install -U pip
11+
- pip3 install awscli
12+
13+
build:
14+
commands:
15+
- env
16+
- echo Packaging Cloudformation and uploading to S3...
17+
- ./package_cloudformation.sh
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: MIT-0
3+
Description: |
4+
Deploy a Lambda function and CloudWatch trigger to inspect SageMaker resources and ensure they are attached to a VPC.
5+
6+
Parameters:
7+
StackSetName:
8+
Type: String
9+
Description: A name to be used across nested stacks
10+
11+
Resources:
12+
SageMakerDetectiveControlExecutionRole:
13+
Type: 'AWS::IAM::Role'
14+
Properties:
15+
AssumeRolePolicyDocument:
16+
Version: 2012-10-17
17+
Statement:
18+
- Effect: Allow
19+
Principal:
20+
Service: lambda.amazonaws.com
21+
Action: 'sts:AssumeRole'
22+
RoleName:
23+
!Join
24+
- ''
25+
-
26+
- !Sub '${StackSetName}-SageMaker-DetectiveControl-'
27+
- !Select
28+
- 4
29+
- !Split
30+
- '-'
31+
- !Select
32+
- 2
33+
- !Split
34+
- /
35+
- !Ref 'AWS::StackId'
36+
Policies:
37+
- PolicyName: LambdaInlineForSageMaker
38+
PolicyDocument:
39+
Version: 2012-10-17
40+
Statement:
41+
- Sid: VisualEditor0
42+
Effect: Allow
43+
Action:
44+
- 'sagemaker:DeleteTags'
45+
- 'sagemaker:DeleteEndpointConfig'
46+
- 'sagemaker:ListTags'
47+
- 'sagemaker:ListTransformJobs'
48+
- 'sagemaker:StopTrainingJob'
49+
- 'sagemaker:DeleteModel'
50+
- 'sagemaker:ListTrainingJobs'
51+
- 'sagemaker:ListHyperParameterTuningJobs'
52+
- 'sagemaker:DeleteEndpoint'
53+
- 'sagemaker:ListModels'
54+
- 'sagemaker:StopTransformJob'
55+
- 'sagemaker:AddTags'
56+
- 'sagemaker:ListEndpoints'
57+
Resource: '*'
58+
ManagedPolicyArns:
59+
- 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
60+
61+
SageMakerVPCDetectiveControl:
62+
Type: 'AWS::Lambda::Function'
63+
Properties:
64+
FunctionName: SageMakerVPCEnforcer
65+
Description: Detective control to enforce VPC attachment of SageMaker resources
66+
Runtime: python3.6
67+
Code: vpc_detective_control.zip
68+
Handler: inspect_sagemaker_resource.lambda_handler
69+
MemorySize: 320
70+
Timeout: 180
71+
Role: !GetAtt SageMakerDetectiveControlExecutionRole.Arn
72+
73+
SageMakerVPCEnforcementRule:
74+
Type: 'AWS::Events::Rule'
75+
DependsOn: SageMakerVPCDetectiveControl
76+
Properties:
77+
Description: The Cloudwatch Rule checking VPC enablement of SageMaker resources
78+
EventPattern:
79+
source:
80+
- aws.sagemaker
81+
detail-type:
82+
- AWS API Call via CloudTrail
83+
detail:
84+
eventSource:
85+
- sagemaker.amazonaws.com
86+
eventName:
87+
- CreateTrainingJob
88+
- CreateModel
89+
Name: SageMakerVPCEnforcementRule
90+
State: ENABLED
91+
Targets:
92+
- Arn: !GetAtt SageMakerVPCDetectiveControl.Arn
93+
Id: SagemakerVPCEnforcementLambda
94+
95+
InvokeLambdaPermission:
96+
Type: 'AWS::Lambda::Permission'
97+
DependsOn: SageMakerVPCEnforcementRule
98+
Properties:
99+
FunctionName: !GetAtt SageMakerVPCDetectiveControl.Arn
100+
Action: 'lambda:InvokeFunction'
101+
Principal: events.amazonaws.com
102+
SourceArn: !GetAtt SageMakerVPCEnforcementRule.Arn

0 commit comments

Comments
 (0)