sagemaker-mlflow 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sagemaker_mlflow-0.1.0/LICENSE +202 -0
- sagemaker_mlflow-0.1.0/MANIFEST.in +12 -0
- sagemaker_mlflow-0.1.0/NOTICE +2 -0
- sagemaker_mlflow-0.1.0/PKG-INFO +109 -0
- sagemaker_mlflow-0.1.0/README.md +72 -0
- sagemaker_mlflow-0.1.0/VERSION +1 -0
- sagemaker_mlflow-0.1.0/pyproject.toml +2 -0
- sagemaker_mlflow-0.1.0/requirements/black_requirements.txt +1 -0
- sagemaker_mlflow-0.1.0/requirements/flake8_requirements.txt +1 -0
- sagemaker_mlflow-0.1.0/requirements/integration_test_requirements.txt +9 -0
- sagemaker_mlflow-0.1.0/requirements/mypy_requirements.txt +2 -0
- sagemaker_mlflow-0.1.0/requirements/prerelease_test_requirements.txt +4 -0
- sagemaker_mlflow-0.1.0/requirements/twine_requirements.txt +1 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow/__init__.py +16 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow/auth.py +96 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow/auth_provider.py +39 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow/exceptions.py +16 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow/mlflow_sagemaker_helpers.py +80 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow/mlflow_sagemaker_registry_store.py +46 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow/mlflow_sagemaker_request_header_provider.py +31 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow/mlflow_sagemaker_store.py +58 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow/presigned_url.py +43 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow.egg-info/PKG-INFO +109 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow.egg-info/SOURCES.txt +29 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow.egg-info/dependency_links.txt +1 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow.egg-info/entry_points.txt +11 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow.egg-info/requires.txt +18 -0
- sagemaker_mlflow-0.1.0/sagemaker_mlflow.egg-info/top_level.txt +1 -0
- sagemaker_mlflow-0.1.0/setup.cfg +7 -0
- sagemaker_mlflow-0.1.0/setup.py +85 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: sagemaker-mlflow
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AWS Plugin for MLFlow with SageMaker
|
|
5
|
+
Home-page: https://github.com/aws/sagemaker-mlflow
|
|
6
|
+
Author: Amazon Web Services
|
|
7
|
+
License: Apache License 2.0
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Natural Language :: English
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Requires-Python: >= 3.8
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
License-File: NOTICE
|
|
21
|
+
Requires-Dist: boto3>=1.34
|
|
22
|
+
Requires-Dist: mlflow>=2.8
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: boto3; extra == "test"
|
|
25
|
+
Requires-Dist: coverage<6.2,>=5.2; extra == "test"
|
|
26
|
+
Requires-Dist: mlflow; extra == "test"
|
|
27
|
+
Requires-Dist: pytest; extra == "test"
|
|
28
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
29
|
+
Requires-Dist: pytest-rerunfailures; extra == "test"
|
|
30
|
+
Requires-Dist: pytest-timeout; extra == "test"
|
|
31
|
+
Requires-Dist: pytest-xdist; extra == "test"
|
|
32
|
+
Requires-Dist: scikit-learn; extra == "test"
|
|
33
|
+
Provides-Extra: test-prerelease
|
|
34
|
+
Requires-Dist: mlflow; extra == "test-prerelease"
|
|
35
|
+
Requires-Dist: packaging; extra == "test-prerelease"
|
|
36
|
+
Requires-Dist: pytest; extra == "test-prerelease"
|
|
37
|
+
|
|
38
|
+
# SageMaker MLFlow Plugin
|
|
39
|
+
|
|
40
|
+
## What does this Plugin do?
|
|
41
|
+
|
|
42
|
+
This plugin generates Signature V4 headers in each outgoing request to the SageMaker MLFlow service and also determines
|
|
43
|
+
the URL of the SageMaker MLFlow service. It generates a token with the SigV4 Algorithm that the service will use to
|
|
44
|
+
conduct Authentication and Authorization.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
To install this plugin, run the following command inside the directory:
|
|
49
|
+
```
|
|
50
|
+
pip install .
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Eventually when the plugin gets distributed, it will be installed with:
|
|
54
|
+
```
|
|
55
|
+
pip install sagemaker-mlflow
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Running this will install the Auth Plugin and mlflow.
|
|
59
|
+
|
|
60
|
+
To install a specific mlflow version
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
pip install .
|
|
64
|
+
pip install mlflow==2.13
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Development details
|
|
68
|
+
|
|
69
|
+
### setup.py
|
|
70
|
+
|
|
71
|
+
`setup.py` Contains the primary entry points for the sdk.
|
|
72
|
+
`install_requires` Installs mlflow.
|
|
73
|
+
`entry_points` Contains the entry points for the sdk. See https://mlflow.org/docs/latest/plugins.html#defining-a-plugin
|
|
74
|
+
for more details.
|
|
75
|
+
|
|
76
|
+
### Running tests
|
|
77
|
+
|
|
78
|
+
#### Setup
|
|
79
|
+
To run tests using tox, run:
|
|
80
|
+
```
|
|
81
|
+
pip install tox
|
|
82
|
+
```
|
|
83
|
+
Installing tox will enable users to run multi-environment tests. On the other hand, if
|
|
84
|
+
running individual tests in a single environment, feel free to continue to use pytest instead.
|
|
85
|
+
|
|
86
|
+
#### Running format checks
|
|
87
|
+
```
|
|
88
|
+
tox -e flake8,black-check,typing,twine
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### Formatting code to comply with format checks
|
|
92
|
+
```
|
|
93
|
+
tox -e black-format
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Running unit tests
|
|
97
|
+
```
|
|
98
|
+
tox --skip-env "black.*|flake8|typing|twine" -- test/unit
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### Running integration tests
|
|
102
|
+
```
|
|
103
|
+
tox --skip-env "black.*|flake8|typing|twine" -- test/integration
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Available test environments by default
|
|
107
|
+
tox.ini contains support for py39, py310, py311, with mlflow 2.11.* and 2.12.*.
|
|
108
|
+
To add test environments on tox for additional versions of python or mlflow, modify the
|
|
109
|
+
environment configs in `envlist`, as well as `deps` and `depends` in `[testenv]`.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# SageMaker MLFlow Plugin
|
|
2
|
+
|
|
3
|
+
## What does this Plugin do?
|
|
4
|
+
|
|
5
|
+
This plugin generates Signature V4 headers in each outgoing request to the SageMaker MLFlow service and also determines
|
|
6
|
+
the URL of the SageMaker MLFlow service. It generates a token with the SigV4 Algorithm that the service will use to
|
|
7
|
+
conduct Authentication and Authorization.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
To install this plugin, run the following command inside the directory:
|
|
12
|
+
```
|
|
13
|
+
pip install .
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Eventually when the plugin gets distributed, it will be installed with:
|
|
17
|
+
```
|
|
18
|
+
pip install sagemaker-mlflow
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Running this will install the Auth Plugin and mlflow.
|
|
22
|
+
|
|
23
|
+
To install a specific mlflow version
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
pip install .
|
|
27
|
+
pip install mlflow==2.13
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Development details
|
|
31
|
+
|
|
32
|
+
### setup.py
|
|
33
|
+
|
|
34
|
+
`setup.py` Contains the primary entry points for the sdk.
|
|
35
|
+
`install_requires` Installs mlflow.
|
|
36
|
+
`entry_points` Contains the entry points for the sdk. See https://mlflow.org/docs/latest/plugins.html#defining-a-plugin
|
|
37
|
+
for more details.
|
|
38
|
+
|
|
39
|
+
### Running tests
|
|
40
|
+
|
|
41
|
+
#### Setup
|
|
42
|
+
To run tests using tox, run:
|
|
43
|
+
```
|
|
44
|
+
pip install tox
|
|
45
|
+
```
|
|
46
|
+
Installing tox will enable users to run multi-environment tests. On the other hand, if
|
|
47
|
+
running individual tests in a single environment, feel free to continue to use pytest instead.
|
|
48
|
+
|
|
49
|
+
#### Running format checks
|
|
50
|
+
```
|
|
51
|
+
tox -e flake8,black-check,typing,twine
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### Formatting code to comply with format checks
|
|
55
|
+
```
|
|
56
|
+
tox -e black-format
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### Running unit tests
|
|
60
|
+
```
|
|
61
|
+
tox --skip-env "black.*|flake8|typing|twine" -- test/unit
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### Running integration tests
|
|
65
|
+
```
|
|
66
|
+
tox --skip-env "black.*|flake8|typing|twine" -- test/integration
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Available test environments by default
|
|
70
|
+
tox.ini contains support for py39, py310, py311, with mlflow 2.11.* and 2.12.*.
|
|
71
|
+
To add test environments on tox for additional versions of python or mlflow, modify the
|
|
72
|
+
environment configs in `envlist`, as well as `deps` and `depends` in `[testenv]`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
black
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
flake8
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
twine
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
import importlib_metadata
|
|
15
|
+
|
|
16
|
+
__version__ = importlib_metadata.version("sagemaker-mlflow")
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
import boto3
|
|
15
|
+
from requests.auth import AuthBase
|
|
16
|
+
from requests.models import PreparedRequest
|
|
17
|
+
|
|
18
|
+
from botocore.auth import SigV4Auth
|
|
19
|
+
from botocore.awsrequest import AWSRequest
|
|
20
|
+
from hashlib import sha256
|
|
21
|
+
import functools
|
|
22
|
+
|
|
23
|
+
SERVICE_NAME = "sagemaker-mlflow"
|
|
24
|
+
PAYLOAD_BUFFER = 1024 * 1024
|
|
25
|
+
EMPTY_SHA256_HASH = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class AuthBoto(AuthBase):
|
|
29
|
+
|
|
30
|
+
def __init__(self, region: str):
|
|
31
|
+
"""Constructor for Authorization Mechanism
|
|
32
|
+
:param region: AWS region eg us-west-2
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
session = boto3.Session()
|
|
36
|
+
self.creds = session.get_credentials()
|
|
37
|
+
self.region = region
|
|
38
|
+
self.sigv4 = SigV4Auth(self.creds, SERVICE_NAME, self.region)
|
|
39
|
+
|
|
40
|
+
def __call__(self, r: PreparedRequest) -> PreparedRequest:
|
|
41
|
+
"""Method to return the prepared request
|
|
42
|
+
:param r: PreparedRequest Base mlflow request
|
|
43
|
+
:return: PreparedRequest Request with SigV4 signed headers
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
url = r.url
|
|
47
|
+
method = r.method
|
|
48
|
+
headers = r.headers
|
|
49
|
+
request_body = r.body
|
|
50
|
+
connection_header = headers["Connection"]
|
|
51
|
+
|
|
52
|
+
headers["X-Amz-Content-SHA256"] = self.get_request_body_header(request_body)
|
|
53
|
+
|
|
54
|
+
# SageMaker Mlflow strips out this header before auth.
|
|
55
|
+
# But boto signs every header even its its uppercase or lower cased.
|
|
56
|
+
if "Connection" in headers:
|
|
57
|
+
connection_header = headers["Connection"]
|
|
58
|
+
del headers["Connection"]
|
|
59
|
+
|
|
60
|
+
# Mlflow encodes spaces as +, Auth prefers %20
|
|
61
|
+
if method == "GET" or method == "DELETE":
|
|
62
|
+
url = url.replace("+", "%20")
|
|
63
|
+
|
|
64
|
+
# Creating a new request with the SigV4 signed headers.
|
|
65
|
+
aws_request = AWSRequest(method=method, url=url, data=r.body, headers=headers)
|
|
66
|
+
self.sigv4.add_auth(aws_request)
|
|
67
|
+
|
|
68
|
+
# Adding back in the connection header.
|
|
69
|
+
final_headers = aws_request.headers
|
|
70
|
+
final_headers["Connection"] = connection_header
|
|
71
|
+
final_request = AWSRequest(
|
|
72
|
+
method=method, url=url, data=r.body, headers=final_headers
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
return final_request.prepare()
|
|
76
|
+
|
|
77
|
+
def get_request_body_header(self, request_body: bytes):
|
|
78
|
+
"""Stripped down version of the botocore method.
|
|
79
|
+
:param request_body: request body
|
|
80
|
+
:return: hex_checksum
|
|
81
|
+
"""
|
|
82
|
+
if request_body and hasattr(request_body, "seek"):
|
|
83
|
+
position = request_body.tell()
|
|
84
|
+
read_chunksize = functools.partial(request_body.read, PAYLOAD_BUFFER)
|
|
85
|
+
checksum = sha256()
|
|
86
|
+
for chunk in iter(read_chunksize, b""):
|
|
87
|
+
checksum.update(chunk)
|
|
88
|
+
hex_checksum = checksum.hexdigest()
|
|
89
|
+
request_body.seek(position)
|
|
90
|
+
return hex_checksum
|
|
91
|
+
elif request_body:
|
|
92
|
+
# The request serialization has ensured that
|
|
93
|
+
# request.body is a bytes() type.
|
|
94
|
+
return sha256(request_body).hexdigest()
|
|
95
|
+
else:
|
|
96
|
+
return EMPTY_SHA256_HASH
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
from sagemaker_mlflow.auth import AuthBoto
|
|
15
|
+
from mlflow import get_tracking_uri
|
|
16
|
+
from sagemaker_mlflow.mlflow_sagemaker_helpers import validate_and_parse_arn
|
|
17
|
+
|
|
18
|
+
AWS_SIGV4_PLUGIN_NAME = "arn"
|
|
19
|
+
|
|
20
|
+
class AuthProvider:
|
|
21
|
+
"""Entry Point class to using the plugin. mlflow will call get_name
|
|
22
|
+
to determine the name of the plugin. get_auth will be called
|
|
23
|
+
when creating the request to put a callback class that will
|
|
24
|
+
generate the Sig v4 token.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def get_name(self) -> str:
|
|
28
|
+
"""Returns the name of the plugin"""
|
|
29
|
+
return AWS_SIGV4_PLUGIN_NAME
|
|
30
|
+
|
|
31
|
+
def get_auth(self) -> AuthBoto:
|
|
32
|
+
"""Returns the callback class(AuthBoto) used for generating the SigV4 header.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
AuthBoto: Callback Object which will calculate the header just before request submission.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
arn = validate_and_parse_arn(get_tracking_uri())
|
|
39
|
+
return AuthBoto(arn.region)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class MlflowSageMakerException(Exception):
|
|
16
|
+
pass
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
from sagemaker_mlflow.exceptions import MlflowSageMakerException
|
|
15
|
+
import os
|
|
16
|
+
import logging
|
|
17
|
+
|
|
18
|
+
class Arn:
|
|
19
|
+
|
|
20
|
+
""" Constructor for Arn Object
|
|
21
|
+
Args:
|
|
22
|
+
tracking_server_arn (str): Tracking Server Arn
|
|
23
|
+
"""
|
|
24
|
+
def __init__(self, arn: str):
|
|
25
|
+
splitted_arn = arn.split(":")
|
|
26
|
+
self.partition = splitted_arn[1]
|
|
27
|
+
self.service = splitted_arn[2]
|
|
28
|
+
self.region = splitted_arn[3]
|
|
29
|
+
self.account = splitted_arn[4]
|
|
30
|
+
self.resource_type = splitted_arn[5].split("/")[0]
|
|
31
|
+
self.resource_id = splitted_arn[5].split("/")[1]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def validate_and_parse_arn(tracking_server_arn: str) -> Arn:
|
|
35
|
+
"""Validates and returns an arn from a string.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
tracking_server_arn (str): Tracking Server Arn
|
|
39
|
+
Returns:
|
|
40
|
+
Arn: Arn Object
|
|
41
|
+
"""
|
|
42
|
+
arn = Arn(tracking_server_arn)
|
|
43
|
+
if (
|
|
44
|
+
arn.service != "sagemaker"
|
|
45
|
+
or not arn.resource_type
|
|
46
|
+
or not arn.resource_id
|
|
47
|
+
):
|
|
48
|
+
raise MlflowSageMakerException(f"{tracking_server_arn} is not a valid arn")
|
|
49
|
+
return arn
|
|
50
|
+
|
|
51
|
+
def get_tracking_server_url(tracking_server_arn: str) -> str:
|
|
52
|
+
"""Returns the url used by SageMaker MLFlow
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
tracking_server_arn (str): Tracking Server Arn
|
|
56
|
+
Returns:
|
|
57
|
+
str: Tracking Server URL.
|
|
58
|
+
"""
|
|
59
|
+
custom_endpoint = os.environ.get("SAGEMAKER_MLFLOW_CUSTOM_ENDPOINT", "")
|
|
60
|
+
if custom_endpoint:
|
|
61
|
+
logging.info(f"Using custom endpoint {custom_endpoint}")
|
|
62
|
+
return custom_endpoint
|
|
63
|
+
arn = validate_and_parse_arn(tracking_server_arn)
|
|
64
|
+
dns_suffix = get_dns_suffix(arn.partition)
|
|
65
|
+
endpoint = f"https://{arn.region}.experiments.sagemaker.{dns_suffix}"
|
|
66
|
+
return endpoint
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def get_dns_suffix(partition: str) -> str:
|
|
70
|
+
"""Returns a DNS suffix for a partition
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
partition (str): Partition that the tracking server resides in.
|
|
74
|
+
Returns:
|
|
75
|
+
str: DNS suffix of the partition
|
|
76
|
+
"""
|
|
77
|
+
if partition == "aws":
|
|
78
|
+
return "aws"
|
|
79
|
+
else:
|
|
80
|
+
raise MlflowSageMakerException(f"Partition {partition} Not supported.")
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from mlflow.store.model_registry.rest_store import RestStore
|
|
2
|
+
from sagemaker_mlflow.mlflow_sagemaker_helpers import get_tracking_server_url
|
|
3
|
+
from mlflow.utils import rest_utils
|
|
4
|
+
from functools import partial
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
class MlflowSageMakerRegistryStore(RestStore):
|
|
8
|
+
|
|
9
|
+
store_uri = ""
|
|
10
|
+
|
|
11
|
+
def __init__(self, store_uri):
|
|
12
|
+
self.store_uri = store_uri
|
|
13
|
+
super().__init__(partial(get_host_creds, store_uri))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Extra environment variables which take precedence for setting the basic/bearer
|
|
17
|
+
# auth on http requests.
|
|
18
|
+
_TRACKING_USERNAME_ENV_VAR = "MLFLOW_TRACKING_USERNAME"
|
|
19
|
+
_TRACKING_PASSWORD_ENV_VAR = "MLFLOW_TRACKING_PASSWORD"
|
|
20
|
+
_TRACKING_TOKEN_ENV_VAR = "MLFLOW_TRACKING_TOKEN"
|
|
21
|
+
|
|
22
|
+
# sets verify param of 'requests.request' function
|
|
23
|
+
# see https://requests.readthedocs.io/en/master/api/
|
|
24
|
+
_TRACKING_INSECURE_TLS_ENV_VAR = "MLFLOW_TRACKING_INSECURE_TLS"
|
|
25
|
+
_TRACKING_SERVER_CERT_PATH_ENV_VAR = "MLFLOW_TRACKING_SERVER_CERT_PATH"
|
|
26
|
+
|
|
27
|
+
# sets cert param of 'requests.request' function
|
|
28
|
+
# see https://requests.readthedocs.io/en/master/api/
|
|
29
|
+
_TRACKING_CLIENT_CERT_PATH_ENV_VAR = "MLFLOW_TRACKING_CLIENT_CERT_PATH"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_host_creds(store_uri):
|
|
33
|
+
"""Configuring mlflow's client"""
|
|
34
|
+
tracking_server_url = get_tracking_server_url(store_uri)
|
|
35
|
+
return rest_utils.MlflowHostCreds(
|
|
36
|
+
host=tracking_server_url,
|
|
37
|
+
username=os.environ.get(_TRACKING_USERNAME_ENV_VAR),
|
|
38
|
+
password=os.environ.get(_TRACKING_PASSWORD_ENV_VAR),
|
|
39
|
+
token=os.environ.get(_TRACKING_TOKEN_ENV_VAR),
|
|
40
|
+
auth="arn",
|
|
41
|
+
# aws_sigv4="False", # Auth provider is used instead for now
|
|
42
|
+
ignore_tls_verification=os.environ.get(_TRACKING_INSECURE_TLS_ENV_VAR)
|
|
43
|
+
== "true",
|
|
44
|
+
client_cert_path=os.environ.get(_TRACKING_CLIENT_CERT_PATH_ENV_VAR),
|
|
45
|
+
server_cert_path=os.environ.get(_TRACKING_SERVER_CERT_PATH_ENV_VAR),
|
|
46
|
+
)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from mlflow.tracking.request_header.abstract_request_header_provider import RequestHeaderProvider
|
|
16
|
+
from mlflow import get_tracking_uri
|
|
17
|
+
|
|
18
|
+
class MlflowSageMakerRequestHeaderProvider(RequestHeaderProvider):
|
|
19
|
+
"""RequestHeaderProvider provided through plugin system"""
|
|
20
|
+
|
|
21
|
+
def in_context(self):
|
|
22
|
+
"""Activates the plugin"""
|
|
23
|
+
return True
|
|
24
|
+
|
|
25
|
+
def request_headers(self):
|
|
26
|
+
"""Returns plugin headers used by SageMaker MLFlow
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
dict: Dictionary containing the headers that are needed for routing.
|
|
30
|
+
"""
|
|
31
|
+
return { "x-mlflow-sm-tracking-server-arn": get_tracking_uri() }
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
from mlflow.store.tracking.rest_store import RestStore
|
|
15
|
+
from mlflow.utils import rest_utils
|
|
16
|
+
import os
|
|
17
|
+
from functools import partial
|
|
18
|
+
from sagemaker_mlflow.mlflow_sagemaker_helpers import get_tracking_server_url
|
|
19
|
+
|
|
20
|
+
# Extra environment variables which take precedence for setting the basic/bearer
|
|
21
|
+
# auth on http requests.
|
|
22
|
+
_TRACKING_USERNAME_ENV_VAR = "MLFLOW_TRACKING_USERNAME"
|
|
23
|
+
_TRACKING_PASSWORD_ENV_VAR = "MLFLOW_TRACKING_PASSWORD"
|
|
24
|
+
_TRACKING_TOKEN_ENV_VAR = "MLFLOW_TRACKING_TOKEN"
|
|
25
|
+
|
|
26
|
+
# sets verify param of 'requests.request' function
|
|
27
|
+
# see https://requests.readthedocs.io/en/master/api/
|
|
28
|
+
_TRACKING_INSECURE_TLS_ENV_VAR = "MLFLOW_TRACKING_INSECURE_TLS"
|
|
29
|
+
_TRACKING_SERVER_CERT_PATH_ENV_VAR = "MLFLOW_TRACKING_SERVER_CERT_PATH"
|
|
30
|
+
|
|
31
|
+
# sets cert param of 'requests.request' function
|
|
32
|
+
# see https://requests.readthedocs.io/en/master/api/
|
|
33
|
+
_TRACKING_CLIENT_CERT_PATH_ENV_VAR = "MLFLOW_TRACKING_CLIENT_CERT_PATH"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class MlflowSageMakerStore(RestStore):
|
|
37
|
+
store_uri = ""
|
|
38
|
+
|
|
39
|
+
def __init__(self, store_uri, artifact_uri):
|
|
40
|
+
self.store_uri = store_uri
|
|
41
|
+
super().__init__(partial(get_host_creds, store_uri))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_host_creds(store_uri) -> rest_utils.MlflowHostCreds:
|
|
45
|
+
"""Configuring mlflow's client"""
|
|
46
|
+
tracking_server_url = get_tracking_server_url(store_uri)
|
|
47
|
+
return rest_utils.MlflowHostCreds(
|
|
48
|
+
host=tracking_server_url,
|
|
49
|
+
username=os.environ.get(_TRACKING_USERNAME_ENV_VAR),
|
|
50
|
+
password=os.environ.get(_TRACKING_PASSWORD_ENV_VAR),
|
|
51
|
+
token=os.environ.get(_TRACKING_TOKEN_ENV_VAR),
|
|
52
|
+
auth="arn",
|
|
53
|
+
# aws_sigv4="False", # Auth provider is used instead for now
|
|
54
|
+
ignore_tls_verification=os.environ.get(_TRACKING_INSECURE_TLS_ENV_VAR)
|
|
55
|
+
== "true",
|
|
56
|
+
client_cert_path=os.environ.get(_TRACKING_CLIENT_CERT_PATH_ENV_VAR),
|
|
57
|
+
server_cert_path=os.environ.get(_TRACKING_SERVER_CERT_PATH_ENV_VAR),
|
|
58
|
+
)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
|
|
16
|
+
import boto3
|
|
17
|
+
import mlflow
|
|
18
|
+
from sagemaker_mlflow.mlflow_sagemaker_helpers import validate_and_parse_arn
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_presigned_url(url_expiration_duration=300, session_duration=5000) -> str:
|
|
22
|
+
""" Creates a presigned url
|
|
23
|
+
|
|
24
|
+
:param url_expiration_duration: First use expiration time of the presigned url
|
|
25
|
+
:param session_duration: Session duration of the presigned url
|
|
26
|
+
|
|
27
|
+
:returns: Authorized Url
|
|
28
|
+
|
|
29
|
+
"""
|
|
30
|
+
arn = validate_and_parse_arn(mlflow.get_tracking_uri())
|
|
31
|
+
custom_endpoint = os.environ.get("SAGEMAKER_ENDPOINT_URL", "")
|
|
32
|
+
if not custom_endpoint:
|
|
33
|
+
sagemaker_client = boto3.client("sagemaker", region_name=arn.region)
|
|
34
|
+
else:
|
|
35
|
+
sagemaker_client = boto3.client("sagemaker", endpoint_url=custom_endpoint, region_name=arn.region)
|
|
36
|
+
|
|
37
|
+
config = {
|
|
38
|
+
"TrackingServerName": arn.resource_id,
|
|
39
|
+
"ExpiresInSeconds": url_expiration_duration,
|
|
40
|
+
"SessionExpirationDurationInSeconds": session_duration
|
|
41
|
+
}
|
|
42
|
+
response = sagemaker_client.create_presigned_mlflow_tracking_server_url(**config)
|
|
43
|
+
return response["AuthorizedUrl"]
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: sagemaker-mlflow
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AWS Plugin for MLFlow with SageMaker
|
|
5
|
+
Home-page: https://github.com/aws/sagemaker-mlflow
|
|
6
|
+
Author: Amazon Web Services
|
|
7
|
+
License: Apache License 2.0
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Natural Language :: English
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Requires-Python: >= 3.8
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
License-File: NOTICE
|
|
21
|
+
Requires-Dist: boto3>=1.34
|
|
22
|
+
Requires-Dist: mlflow>=2.8
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: boto3; extra == "test"
|
|
25
|
+
Requires-Dist: coverage<6.2,>=5.2; extra == "test"
|
|
26
|
+
Requires-Dist: mlflow; extra == "test"
|
|
27
|
+
Requires-Dist: pytest; extra == "test"
|
|
28
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
29
|
+
Requires-Dist: pytest-rerunfailures; extra == "test"
|
|
30
|
+
Requires-Dist: pytest-timeout; extra == "test"
|
|
31
|
+
Requires-Dist: pytest-xdist; extra == "test"
|
|
32
|
+
Requires-Dist: scikit-learn; extra == "test"
|
|
33
|
+
Provides-Extra: test-prerelease
|
|
34
|
+
Requires-Dist: mlflow; extra == "test-prerelease"
|
|
35
|
+
Requires-Dist: packaging; extra == "test-prerelease"
|
|
36
|
+
Requires-Dist: pytest; extra == "test-prerelease"
|
|
37
|
+
|
|
38
|
+
# SageMaker MLFlow Plugin
|
|
39
|
+
|
|
40
|
+
## What does this Plugin do?
|
|
41
|
+
|
|
42
|
+
This plugin generates Signature V4 headers in each outgoing request to the SageMaker MLFlow service and also determines
|
|
43
|
+
the URL of the SageMaker MLFlow service. It generates a token with the SigV4 Algorithm that the service will use to
|
|
44
|
+
conduct Authentication and Authorization.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
To install this plugin, run the following command inside the directory:
|
|
49
|
+
```
|
|
50
|
+
pip install .
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Eventually when the plugin gets distributed, it will be installed with:
|
|
54
|
+
```
|
|
55
|
+
pip install sagemaker-mlflow
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Running this will install the Auth Plugin and mlflow.
|
|
59
|
+
|
|
60
|
+
To install a specific mlflow version
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
pip install .
|
|
64
|
+
pip install mlflow==2.13
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Development details
|
|
68
|
+
|
|
69
|
+
### setup.py
|
|
70
|
+
|
|
71
|
+
`setup.py` Contains the primary entry points for the sdk.
|
|
72
|
+
`install_requires` Installs mlflow.
|
|
73
|
+
`entry_points` Contains the entry points for the sdk. See https://mlflow.org/docs/latest/plugins.html#defining-a-plugin
|
|
74
|
+
for more details.
|
|
75
|
+
|
|
76
|
+
### Running tests
|
|
77
|
+
|
|
78
|
+
#### Setup
|
|
79
|
+
To run tests using tox, run:
|
|
80
|
+
```
|
|
81
|
+
pip install tox
|
|
82
|
+
```
|
|
83
|
+
Installing tox will enable users to run multi-environment tests. On the other hand, if
|
|
84
|
+
running individual tests in a single environment, feel free to continue to use pytest instead.
|
|
85
|
+
|
|
86
|
+
#### Running format checks
|
|
87
|
+
```
|
|
88
|
+
tox -e flake8,black-check,typing,twine
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### Formatting code to comply with format checks
|
|
92
|
+
```
|
|
93
|
+
tox -e black-format
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Running unit tests
|
|
97
|
+
```
|
|
98
|
+
tox --skip-env "black.*|flake8|typing|twine" -- test/unit
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### Running integration tests
|
|
102
|
+
```
|
|
103
|
+
tox --skip-env "black.*|flake8|typing|twine" -- test/integration
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Available test environments by default
|
|
107
|
+
tox.ini contains support for py39, py310, py311, with mlflow 2.11.* and 2.12.*.
|
|
108
|
+
To add test environments on tox for additional versions of python or mlflow, modify the
|
|
109
|
+
environment configs in `envlist`, as well as `deps` and `depends` in `[testenv]`.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
NOTICE
|
|
4
|
+
README.md
|
|
5
|
+
VERSION
|
|
6
|
+
pyproject.toml
|
|
7
|
+
setup.cfg
|
|
8
|
+
setup.py
|
|
9
|
+
requirements/black_requirements.txt
|
|
10
|
+
requirements/flake8_requirements.txt
|
|
11
|
+
requirements/integration_test_requirements.txt
|
|
12
|
+
requirements/mypy_requirements.txt
|
|
13
|
+
requirements/prerelease_test_requirements.txt
|
|
14
|
+
requirements/twine_requirements.txt
|
|
15
|
+
sagemaker_mlflow/__init__.py
|
|
16
|
+
sagemaker_mlflow/auth.py
|
|
17
|
+
sagemaker_mlflow/auth_provider.py
|
|
18
|
+
sagemaker_mlflow/exceptions.py
|
|
19
|
+
sagemaker_mlflow/mlflow_sagemaker_helpers.py
|
|
20
|
+
sagemaker_mlflow/mlflow_sagemaker_registry_store.py
|
|
21
|
+
sagemaker_mlflow/mlflow_sagemaker_request_header_provider.py
|
|
22
|
+
sagemaker_mlflow/mlflow_sagemaker_store.py
|
|
23
|
+
sagemaker_mlflow/presigned_url.py
|
|
24
|
+
sagemaker_mlflow.egg-info/PKG-INFO
|
|
25
|
+
sagemaker_mlflow.egg-info/SOURCES.txt
|
|
26
|
+
sagemaker_mlflow.egg-info/dependency_links.txt
|
|
27
|
+
sagemaker_mlflow.egg-info/entry_points.txt
|
|
28
|
+
sagemaker_mlflow.egg-info/requires.txt
|
|
29
|
+
sagemaker_mlflow.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[mlflow.model_registry_store]
|
|
2
|
+
arn = sagemaker_mlflow.mlflow_sagemaker_registry_store:MlflowSageMakerRegistryStore
|
|
3
|
+
|
|
4
|
+
[mlflow.request_auth_provider]
|
|
5
|
+
arn = sagemaker_mlflow.auth_provider:AuthProvider
|
|
6
|
+
|
|
7
|
+
[mlflow.request_header_provider]
|
|
8
|
+
arn = sagemaker_mlflow.mlflow_sagemaker_request_header_provider:MlflowSageMakerRequestHeaderProvider
|
|
9
|
+
|
|
10
|
+
[mlflow.tracking_store]
|
|
11
|
+
arn = sagemaker_mlflow.mlflow_sagemaker_store:MlflowSageMakerStore
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sagemaker_mlflow
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
|
|
14
|
+
"""
|
|
15
|
+
sagemaker-mlflow plugin installation.
|
|
16
|
+
"""
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from setuptools import setup, find_packages
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def read(fname):
|
|
23
|
+
"""
|
|
24
|
+
Args:
|
|
25
|
+
fname:
|
|
26
|
+
"""
|
|
27
|
+
with open(os.path.join(os.path.dirname(__file__), fname), "r") as f:
|
|
28
|
+
contents = f.read()
|
|
29
|
+
return contents
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def read_version():
|
|
33
|
+
return read("VERSION").strip()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def read_requirements(filename):
|
|
37
|
+
"""Reads requirements file which lists package dependencies.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
filename: type(str) Relative file path of requirements.txt file
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
list of dependencies extracted from file
|
|
44
|
+
"""
|
|
45
|
+
with open(os.path.abspath(filename)) as fp:
|
|
46
|
+
deps = [line.strip() for line in fp.readlines()]
|
|
47
|
+
return deps
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
test_requirements = read_requirements("requirements/integration_test_requirements.txt")
|
|
51
|
+
test_prerelease_requirements = read_requirements("requirements/prerelease_test_requirements.txt")
|
|
52
|
+
|
|
53
|
+
setup(
|
|
54
|
+
name="sagemaker-mlflow",
|
|
55
|
+
packages=find_packages(),
|
|
56
|
+
author="Amazon Web Services",
|
|
57
|
+
license="Apache License 2.0",
|
|
58
|
+
url = 'https://github.com/aws/sagemaker-mlflow',
|
|
59
|
+
classifiers=[
|
|
60
|
+
"Development Status :: 5 - Production/Stable",
|
|
61
|
+
"Intended Audience :: Developers",
|
|
62
|
+
"Natural Language :: English",
|
|
63
|
+
"License :: OSI Approved :: Apache Software License",
|
|
64
|
+
"Programming Language :: Python",
|
|
65
|
+
"Programming Language :: Python :: 3.8",
|
|
66
|
+
"Programming Language :: Python :: 3.9",
|
|
67
|
+
"Programming Language :: Python :: 3.10",
|
|
68
|
+
"Programming Language :: Python :: 3.11",
|
|
69
|
+
],
|
|
70
|
+
# Require MLFlow as a dependency of the plugin, so that plugin users can
|
|
71
|
+
# simply install the plugin and then immediately use it with MLflow
|
|
72
|
+
install_requires=["boto3>=1.34", "mlflow>=2.8"],
|
|
73
|
+
extras_require={"test": test_requirements, "test_prerelease": test_prerelease_requirements},
|
|
74
|
+
python_requires=">= 3.8",
|
|
75
|
+
entry_points={
|
|
76
|
+
"mlflow.tracking_store": "arn=sagemaker_mlflow.mlflow_sagemaker_store:MlflowSageMakerStore",
|
|
77
|
+
"mlflow.request_auth_provider": "arn=sagemaker_mlflow.auth_provider:AuthProvider",
|
|
78
|
+
"mlflow.request_header_provider": "arn=sagemaker_mlflow.mlflow_sagemaker_request_header_provider:MlflowSageMakerRequestHeaderProvider",
|
|
79
|
+
"mlflow.model_registry_store": "arn=sagemaker_mlflow.mlflow_sagemaker_registry_store:MlflowSageMakerRegistryStore"
|
|
80
|
+
},
|
|
81
|
+
version=read_version(),
|
|
82
|
+
description="AWS Plugin for MLFlow with SageMaker",
|
|
83
|
+
long_description=read("README.md"),
|
|
84
|
+
long_description_content_type="text/markdown",
|
|
85
|
+
)
|