airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [32/38] incubator-airflow-site git commit: Docs from 1.10.1
Date Thu, 29 Nov 2018 15:58:30 GMT
http://git-wip-us.apache.org/repos/asf/incubator-airflow-site/blob/1f06fa0e/_modules/airflow/contrib/hooks/sagemaker_hook.html
----------------------------------------------------------------------
diff --git a/_modules/airflow/contrib/hooks/sagemaker_hook.html b/_modules/airflow/contrib/hooks/sagemaker_hook.html
new file mode 100644
index 0000000..d501097
--- /dev/null
+++ b/_modules/airflow/contrib/hooks/sagemaker_hook.html
@@ -0,0 +1,972 @@
+
+
+<!DOCTYPE html>
+<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
+<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
+<head>
+  <meta charset="utf-8">
+  
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  
+  <title>airflow.contrib.hooks.sagemaker_hook &mdash; Airflow Documentation</title>
+  
+
+  
+  
+  
+  
+
+  
+
+  
+  
+    
+
+  
+
+  <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
+  <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
+    <link rel="index" title="Index" href="../../../../genindex.html" />
+    <link rel="search" title="Search" href="../../../../search.html" /> 
+
+  
+  <script src="../../../../_static/js/modernizr.min.js"></script>
+
+</head>
+
+<body class="wy-body-for-nav">
+
+   
+  <div class="wy-grid-for-nav">
+
+    
+    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
+      <div class="wy-side-scroll">
+        <div class="wy-side-nav-search">
+          
+
+          
+            <a href="../../../../index.html" class="icon icon-home"> Airflow
+          
+
+          
+          </a>
+
+          
+            
+            
+          
+
+          
+<div role="search">
+  <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
+    <input type="text" name="q" placeholder="Search docs" />
+    <input type="hidden" name="check_keywords" value="yes" />
+    <input type="hidden" name="area" value="default" />
+  </form>
+</div>
+
+          
+        </div>
+
+        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
+          
+            
+            
+              
+            
+            
+              <ul>
+<li class="toctree-l1"><a class="reference internal" href="../../../../project.html">Project</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../license.html">License</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../start.html">Quick Start</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../installation.html">Installation</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../tutorial.html">Tutorial</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../howto/index.html">How-to Guides</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../ui.html">UI / Screenshots</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../concepts.html">Concepts</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../profiling.html">Data Profiling</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../cli.html">Command Line Interface</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../scheduler.html">Scheduling &amp; Triggers</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../plugins.html">Plugins</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../security.html">Security</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../timezone.html">Time zones</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../api.html">Experimental Rest API</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../integration.html">Integration</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../lineage.html">Lineage</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../faq.html">FAQ</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../code.html">API Reference</a></li>
+</ul>
+
+            
+          
+        </div>
+      </div>
+    </nav>
+
+    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
+
+      
+      <nav class="wy-nav-top" aria-label="top navigation">
+        
+          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
+          <a href="../../../../index.html">Airflow</a>
+        
+      </nav>
+
+
+      <div class="wy-nav-content">
+        
+        <div class="rst-content">
+        
+          
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<div role="navigation" aria-label="breadcrumbs navigation">
+
+  <ul class="wy-breadcrumbs">
+    
+      <li><a href="../../../../index.html">Docs</a> &raquo;</li>
+        
+          <li><a href="../../../index.html">Module code</a> &raquo;</li>
+        
+      <li>airflow.contrib.hooks.sagemaker_hook</li>
+    
+    
+      <li class="wy-breadcrumbs-aside">
+        
+      </li>
+    
+  </ul>
+
+  
+  <hr/>
+</div>
+          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
+           <div itemprop="articleBody">
+            
+  <h1>Source code for airflow.contrib.hooks.sagemaker_hook</h1><div class="highlight"><pre>
+<span></span><span class="c1"># -*- coding: utf-8 -*-</span>
+<span class="c1">#</span>
+<span class="c1"># Licensed to the Apache Software Foundation (ASF) under one</span>
+<span class="c1"># or more contributor license agreements.  See the NOTICE file</span>
+<span class="c1"># distributed with this work for additional information</span>
+<span class="c1"># regarding copyright ownership.  The ASF licenses this file</span>
+<span class="c1"># to you under the Apache License, Version 2.0 (the</span>
+<span class="c1"># &quot;License&quot;); you may not use this file except in compliance</span>
+<span class="c1"># with the License.  You may obtain a copy of the License at</span>
+<span class="c1">#</span>
+<span class="c1">#   http://www.apache.org/licenses/LICENSE-2.0</span>
+<span class="c1">#</span>
+<span class="c1"># Unless required by applicable law or agreed to in writing,</span>
+<span class="c1"># software distributed under the License is distributed on an</span>
+<span class="c1"># &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY</span>
+<span class="c1"># KIND, either express or implied.  See the License for the</span>
+<span class="c1"># specific language governing permissions and limitations</span>
+<span class="c1"># under the License.</span>
+<span class="kn">import</span> <span class="nn">tarfile</span>
+<span class="kn">import</span> <span class="nn">tempfile</span>
+<span class="kn">import</span> <span class="nn">time</span>
+<span class="kn">import</span> <span class="nn">os</span>
+<span class="kn">import</span> <span class="nn">collections</span>
+
+<span class="kn">import</span> <span class="nn">botocore.config</span>
+<span class="kn">from</span> <span class="nn">botocore.exceptions</span> <span class="k">import</span> <span class="n">ClientError</span>
+
+<span class="kn">from</span> <span class="nn">airflow.exceptions</span> <span class="k">import</span> <span class="n">AirflowException</span>
+<span class="kn">from</span> <span class="nn">airflow.contrib.hooks.aws_hook</span> <span class="k">import</span> <span class="n">AwsHook</span>
+<span class="kn">from</span> <span class="nn">airflow.hooks.S3_hook</span> <span class="k">import</span> <span class="n">S3Hook</span>
+<span class="kn">from</span> <span class="nn">airflow.utils</span> <span class="k">import</span> <span class="n">timezone</span>
+
+
+<span class="k">class</span> <span class="nc">LogState</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+    <span class="n">STARTING</span> <span class="o">=</span> <span class="mi">1</span>
+    <span class="n">WAIT_IN_PROGRESS</span> <span class="o">=</span> <span class="mi">2</span>
+    <span class="n">TAILING</span> <span class="o">=</span> <span class="mi">3</span>
+    <span class="n">JOB_COMPLETE</span> <span class="o">=</span> <span class="mi">4</span>
+    <span class="n">COMPLETE</span> <span class="o">=</span> <span class="mi">5</span>
+
+
+<span class="c1"># Position is a tuple that includes the last read timestamp and the number of items that were read</span>
+<span class="c1"># at that time. This is used to figure out which event to start with on the next read.</span>
+<span class="n">Position</span> <span class="o">=</span> <span class="n">collections</span><span class="o">.</span><span class="n">namedtuple</span><span class="p">(</span><span class="s1">&#39;Position&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;timestamp&#39;</span><span class="p">,</span> <span class="s1">&#39;skip&#39;</span><span class="p">])</span>
+
+
+<span class="k">def</span> <span class="nf">argmin</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="n">f</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;Return the index, i, in arr that minimizes f(arr[i])&quot;&quot;&quot;</span>
+    <span class="n">m</span> <span class="o">=</span> <span class="kc">None</span>
+    <span class="n">i</span> <span class="o">=</span> <span class="kc">None</span>
+    <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">item</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">arr</span><span class="p">):</span>
+        <span class="k">if</span> <span class="n">item</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
+            <span class="k">if</span> <span class="n">m</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">f</span><span class="p">(</span><span class="n">item</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">m</span><span class="p">:</span>
+                <span class="n">m</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
+                <span class="n">i</span> <span class="o">=</span> <span class="n">idx</span>
+    <span class="k">return</span> <span class="n">i</span>
+
+
+<span class="k">def</span> <span class="nf">secondary_training_status_changed</span><span class="p">(</span><span class="n">current_job_description</span><span class="p">,</span> <span class="n">prev_job_description</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Returns true if training job&#39;s secondary status message has changed.</span>
+
+<span class="sd">    :param current_job_description: Current job description, returned from DescribeTrainingJob call.</span>
+<span class="sd">    :type current_job_description: dict</span>
+<span class="sd">    :param prev_job_description: Previous job description, returned from DescribeTrainingJob call.</span>
+<span class="sd">    :type prev_job_description: dict</span>
+
+<span class="sd">    :return: Whether the secondary status message of a training job changed or not.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">current_secondary_status_transitions</span> <span class="o">=</span> <span class="n">current_job_description</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;SecondaryStatusTransitions&#39;</span><span class="p">)</span>
+    <span class="k">if</span> <span class="n">current_secondary_status_transitions</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">current_secondary_status_transitions</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
+        <span class="k">return</span> <span class="kc">False</span>
+
+    <span class="n">prev_job_secondary_status_transitions</span> <span class="o">=</span> <span class="n">prev_job_description</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;SecondaryStatusTransitions&#39;</span><span class="p">)</span> \
+        <span class="k">if</span> <span class="n">prev_job_description</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>
+
+    <span class="n">last_message</span> <span class="o">=</span> <span class="n">prev_job_secondary_status_transitions</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="s1">&#39;StatusMessage&#39;</span><span class="p">]</span> \
+        <span class="k">if</span> <span class="n">prev_job_secondary_status_transitions</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> \
+        <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">prev_job_secondary_status_transitions</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="s1">&#39;&#39;</span>
+
+    <span class="n">message</span> <span class="o">=</span> <span class="n">current_job_description</span><span class="p">[</span><span class="s1">&#39;SecondaryStatusTransitions&#39;</span><span class="p">][</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="s1">&#39;StatusMessage&#39;</span><span class="p">]</span>
+
+    <span class="k">return</span> <span class="n">message</span> <span class="o">!=</span> <span class="n">last_message</span>
+
+
+<span class="k">def</span> <span class="nf">secondary_training_status_message</span><span class="p">(</span><span class="n">job_description</span><span class="p">,</span> <span class="n">prev_description</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Returns a string contains start time and the secondary training job status message.</span>
+
+<span class="sd">    :param job_description: Returned response from DescribeTrainingJob call</span>
+<span class="sd">    :type job_description: dict</span>
+<span class="sd">    :param prev_description: Previous job description from DescribeTrainingJob call</span>
+<span class="sd">    :type prev_description: dict</span>
+
+<span class="sd">    :return: Job status string to be printed.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="k">if</span> <span class="n">job_description</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">job_description</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;SecondaryStatusTransitions&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">None</span>\
+            <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">job_description</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;SecondaryStatusTransitions&#39;</span><span class="p">))</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
+        <span class="k">return</span> <span class="s1">&#39;&#39;</span>
+
+    <span class="n">prev_description_secondary_transitions</span> <span class="o">=</span> <span class="n">prev_description</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;SecondaryStatusTransitions&#39;</span><span class="p">)</span>\
+        <span class="k">if</span> <span class="n">prev_description</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="kc">None</span>
+    <span class="n">prev_transitions_num</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">prev_description</span><span class="p">[</span><span class="s1">&#39;SecondaryStatusTransitions&#39;</span><span class="p">])</span>\
+        <span class="k">if</span> <span class="n">prev_description_secondary_transitions</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="mi">0</span>
+    <span class="n">current_transitions</span> <span class="o">=</span> <span class="n">job_description</span><span class="p">[</span><span class="s1">&#39;SecondaryStatusTransitions&#39;</span><span class="p">]</span>
+
+    <span class="n">transitions_to_print</span> <span class="o">=</span> <span class="n">current_transitions</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">:]</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">current_transitions</span><span class="p">)</span> <span class="o">==</span> <span class="n">prev_transitions_num</span> <span class="k">else</span> \
+        <span class="n">current_transitions</span><span class="p">[</span><span class="n">prev_transitions_num</span> <span class="o">-</span> <span class="nb">len</span><span class="p">(</span><span class="n">current_transitions</span><span class="p">):]</span>
+
+    <span class="n">status_strs</span> <span class="o">=</span> <span class="p">[]</span>
+    <span class="k">for</span> <span class="n">transition</span> <span class="ow">in</span> <span class="n">transitions_to_print</span><span class="p">:</span>
+        <span class="n">message</span> <span class="o">=</span> <span class="n">transition</span><span class="p">[</span><span class="s1">&#39;StatusMessage&#39;</span><span class="p">]</span>
+        <span class="n">time_str</span> <span class="o">=</span> <span class="n">timezone</span><span class="o">.</span><span class="n">convert_to_utc</span><span class="p">(</span><span class="n">job_description</span><span class="p">[</span><span class="s1">&#39;LastModifiedTime&#39;</span><span class="p">])</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1"> %H:%M:%S&#39;</span><span class="p">)</span>
+        <span class="n">status_strs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{}</span><span class="s1"> </span><span class="si">{}</span><span class="s1"> - </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">time_str</span><span class="p">,</span> <span class="n">transition</span><span class="p">[</span><span class="s1">&#39;Status&#39;</span><span class="p">],</span> <span class="n">message</span><span class="p">))</span>
+
+    <span class="k">return</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">status_strs</span><span class="p">)</span>
+
+
+<div class="viewcode-block" id="SageMakerHook"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook">[docs]</a><span class="k">class</span> <span class="nc">SageMakerHook</span><span class="p">(</span><span class="n">AwsHook</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Interact with Amazon SageMaker.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">non_terminal_states</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;InProgress&#39;</span><span class="p">,</span> <span class="s1">&#39;Stopping&#39;</span><span class="p">}</span>
+    <span class="n">endpoint_non_terminal_states</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;Creating&#39;</span><span class="p">,</span> <span class="s1">&#39;Updating&#39;</span><span class="p">,</span> <span class="s1">&#39;SystemUpdating&#39;</span><span class="p">,</span>
+                                    <span class="s1">&#39;RollingBack&#39;</span><span class="p">,</span> <span class="s1">&#39;Deleting&#39;</span><span class="p">}</span>
+    <span class="n">failed_states</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;Failed&#39;</span><span class="p">}</span>
+
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
+                 <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+        <span class="nb">super</span><span class="p">(</span><span class="n">SageMakerHook</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">s3_hook</span> <span class="o">=</span> <span class="n">S3Hook</span><span class="p">(</span><span class="n">aws_conn_id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">aws_conn_id</span><span class="p">)</span>
+
+<div class="viewcode-block" id="SageMakerHook.tar_and_s3_upload"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.tar_and_s3_upload">[docs]</a>    <span class="k">def</span> <span class="nf">tar_and_s3_upload</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">bucket</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Tar the local file or directory and upload to s3</span>
+
+<span class="sd">        :param path: local file or directory</span>
+<span class="sd">        :type path: str</span>
+<span class="sd">        :param key: s3 key</span>
+<span class="sd">        :type key: str</span>
+<span class="sd">        :param bucket: s3 bucket</span>
+<span class="sd">        :type bucket: str</span>
+<span class="sd">        :return: None</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">with</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">TemporaryFile</span><span class="p">()</span> <span class="k">as</span> <span class="n">temp_file</span><span class="p">:</span>
+            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
+                <span class="n">files</span> <span class="o">=</span> <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">path</span><span class="p">)]</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">files</span> <span class="o">=</span> <span class="p">[</span><span class="n">path</span><span class="p">]</span>
+            <span class="k">with</span> <span class="n">tarfile</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">mode</span><span class="o">=</span><span class="s1">&#39;w:gz&#39;</span><span class="p">,</span> <span class="n">fileobj</span><span class="o">=</span><span class="n">temp_file</span><span class="p">)</span> <span class="k">as</span> <span class="n">tar_file</span><span class="p">:</span>
+                <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span>
+                    <span class="n">tar_file</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">arcname</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">f</span><span class="p">))</span>
+            <span class="n">temp_file</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">s3_hook</span><span class="o">.</span><span class="n">load_file_obj</span><span class="p">(</span><span class="n">temp_file</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">bucket</span><span class="p">,</span> <span class="n">replace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.configure_s3_resources"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.configure_s3_resources">[docs]</a>    <span class="k">def</span> <span class="nf">configure_s3_resources</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Extract the S3 operations from the configuration and execute them.</span>
+
+<span class="sd">        :param config: config of SageMaker operation</span>
+<span class="sd">        :type config: dict</span>
+<span class="sd">        :return: dict</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">s3_operations</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;S3Operations&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="n">s3_operations</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
+            <span class="n">create_bucket_ops</span> <span class="o">=</span> <span class="n">s3_operations</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;S3CreateBucket&#39;</span><span class="p">,</span> <span class="p">[])</span>
+            <span class="n">upload_ops</span> <span class="o">=</span> <span class="n">s3_operations</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;S3Upload&#39;</span><span class="p">,</span> <span class="p">[])</span>
+            <span class="k">for</span> <span class="n">op</span> <span class="ow">in</span> <span class="n">create_bucket_ops</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">s3_hook</span><span class="o">.</span><span class="n">create_bucket</span><span class="p">(</span><span class="n">bucket_name</span><span class="o">=</span><span class="n">op</span><span class="p">[</span><span class="s1">&#39;Bucket&#39;</span><span class="p">])</span>
+            <span class="k">for</span> <span class="n">op</span> <span class="ow">in</span> <span class="n">upload_ops</span><span class="p">:</span>
+                <span class="k">if</span> <span class="n">op</span><span class="p">[</span><span class="s1">&#39;Tar&#39;</span><span class="p">]:</span>
+                    <span class="bp">self</span><span class="o">.</span><span class="n">tar_and_s3_upload</span><span class="p">(</span><span class="n">op</span><span class="p">[</span><span class="s1">&#39;Path&#39;</span><span class="p">],</span> <span class="n">op</span><span class="p">[</span><span class="s1">&#39;Key&#39;</span><span class="p">],</span>
+                                           <span class="n">op</span><span class="p">[</span><span class="s1">&#39;Bucket&#39;</span><span class="p">])</span>
+                <span class="k">else</span><span class="p">:</span>
+                    <span class="bp">self</span><span class="o">.</span><span class="n">s3_hook</span><span class="o">.</span><span class="n">load_file</span><span class="p">(</span><span class="n">op</span><span class="p">[</span><span class="s1">&#39;Path&#39;</span><span class="p">],</span> <span class="n">op</span><span class="p">[</span><span class="s1">&#39;Key&#39;</span><span class="p">],</span>
+                                           <span class="n">op</span><span class="p">[</span><span class="s1">&#39;Bucket&#39;</span><span class="p">])</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.check_s3_url"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.check_s3_url">[docs]</a>    <span class="k">def</span> <span class="nf">check_s3_url</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s3url</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Check if an S3 URL exists</span>
+
+<span class="sd">        :param s3url: S3 url</span>
+<span class="sd">        :type s3url:str</span>
+<span class="sd">        :return: bool</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">bucket</span><span class="p">,</span> <span class="n">key</span> <span class="o">=</span> <span class="n">S3Hook</span><span class="o">.</span><span class="n">parse_s3_url</span><span class="p">(</span><span class="n">s3url</span><span class="p">)</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">s3_hook</span><span class="o">.</span><span class="n">check_for_bucket</span><span class="p">(</span><span class="n">bucket_name</span><span class="o">=</span><span class="n">bucket</span><span class="p">):</span>
+            <span class="k">raise</span> <span class="n">AirflowException</span><span class="p">(</span>
+                <span class="s2">&quot;The input S3 Bucket </span><span class="si">{}</span><span class="s2"> does not exist &quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">bucket</span><span class="p">))</span>
+        <span class="k">if</span> <span class="n">key</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">s3_hook</span><span class="o">.</span><span class="n">check_for_key</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="n">key</span><span class="p">,</span> <span class="n">bucket_name</span><span class="o">=</span><span class="n">bucket</span><span class="p">)</span>\
+           <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">s3_hook</span><span class="o">.</span><span class="n">check_for_prefix</span><span class="p">(</span>
+                <span class="n">prefix</span><span class="o">=</span><span class="n">key</span><span class="p">,</span> <span class="n">bucket_name</span><span class="o">=</span><span class="n">bucket</span><span class="p">,</span> <span class="n">delimiter</span><span class="o">=</span><span class="s1">&#39;/&#39;</span><span class="p">):</span>
+            <span class="c1"># check if s3 key exists in the case user provides a single file</span>
+            <span class="c1"># or if s3 prefix exists in the case user provides multiple files in</span>
+            <span class="c1"># a prefix</span>
+            <span class="k">raise</span> <span class="n">AirflowException</span><span class="p">(</span><span class="s2">&quot;The input S3 Key &quot;</span>
+                                   <span class="s2">&quot;or Prefix </span><span class="si">{}</span><span class="s2"> does not exist in the Bucket </span><span class="si">{}</span><span class="s2">&quot;</span>
+                                   <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">s3url</span><span class="p">,</span> <span class="n">bucket</span><span class="p">))</span>
+        <span class="k">return</span> <span class="kc">True</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.check_training_config"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.check_training_config">[docs]</a>    <span class="k">def</span> <span class="nf">check_training_config</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">training_config</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Check if a training configuration is valid</span>
+
+<span class="sd">        :param training_config: training_config</span>
+<span class="sd">        :type training_config: dict</span>
+<span class="sd">        :return: None</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">for</span> <span class="n">channel</span> <span class="ow">in</span> <span class="n">training_config</span><span class="p">[</span><span class="s1">&#39;InputDataConfig&#39;</span><span class="p">]:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">check_s3_url</span><span class="p">(</span><span class="n">channel</span><span class="p">[</span><span class="s1">&#39;DataSource&#39;</span><span class="p">][</span><span class="s1">&#39;S3DataSource&#39;</span><span class="p">][</span><span class="s1">&#39;S3Uri&#39;</span><span class="p">])</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.check_tuning_config"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.check_tuning_config">[docs]</a>    <span class="k">def</span> <span class="nf">check_tuning_config</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tuning_config</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Check if a tuning configuration is valid</span>
+
+<span class="sd">        :param tuning_config: tuning_config</span>
+<span class="sd">        :type tuning_config: dict</span>
+<span class="sd">        :return: None</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">for</span> <span class="n">channel</span> <span class="ow">in</span> <span class="n">tuning_config</span><span class="p">[</span><span class="s1">&#39;TrainingJobDefinition&#39;</span><span class="p">][</span><span class="s1">&#39;InputDataConfig&#39;</span><span class="p">]:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">check_s3_url</span><span class="p">(</span><span class="n">channel</span><span class="p">[</span><span class="s1">&#39;DataSource&#39;</span><span class="p">][</span><span class="s1">&#39;S3DataSource&#39;</span><span class="p">][</span><span class="s1">&#39;S3Uri&#39;</span><span class="p">])</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.get_conn"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.get_conn">[docs]</a>    <span class="k">def</span> <span class="nf">get_conn</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Establish an AWS connection for SageMaker</span>
+
+<span class="sd">        :return: a boto3 SageMaker client</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_client_type</span><span class="p">(</span><span class="s1">&#39;sagemaker&#39;</span><span class="p">)</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.get_log_conn"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.get_log_conn">[docs]</a>    <span class="k">def</span> <span class="nf">get_log_conn</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Establish an AWS connection for retrieving logs during training</span>
+
+<span class="sd">        :return: a boto3 CloudWatchLog client</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">config</span> <span class="o">=</span> <span class="n">botocore</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">Config</span><span class="p">(</span><span class="n">retries</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;max_attempts&#39;</span><span class="p">:</span> <span class="mi">15</span><span class="p">})</span>
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_client_type</span><span class="p">(</span><span class="s1">&#39;logs&#39;</span><span class="p">,</span> <span class="n">config</span><span class="o">=</span><span class="n">config</span><span class="p">)</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.log_stream"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.log_stream">[docs]</a>    <span class="k">def</span> <span class="nf">log_stream</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">log_group</span><span class="p">,</span> <span class="n">stream_name</span><span class="p">,</span> <span class="n">start_time</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">skip</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        A generator for log items in a single stream. This will yield all the</span>
+<span class="sd">        items that are available at the current moment.</span>
+
+<span class="sd">        :param log_group: The name of the log group.</span>
+<span class="sd">        :type log_group: str</span>
+<span class="sd">        :param stream_name: The name of the specific stream.</span>
+<span class="sd">        :type stream_name: str</span>
+<span class="sd">        :param start_time: The time stamp value to start reading the logs from (default: 0).</span>
+<span class="sd">        :type start_time: int</span>
+<span class="sd">        :param skip: The number of log entries to skip at the start (default: 0).</span>
+<span class="sd">            This is for when there are multiple entries at the same timestamp.</span>
+<span class="sd">        :type skip: int</span>
+<span class="sd">        :return:A CloudWatch log event with the following key-value pairs:</span>
+<span class="sd">            &#39;timestamp&#39; (int): The time in milliseconds of the event.</span>
+<span class="sd">            &#39;message&#39; (str): The log event data.</span>
+<span class="sd">            &#39;ingestionTime&#39; (int): The time in milliseconds the event was ingested.</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="n">next_token</span> <span class="o">=</span> <span class="kc">None</span>
+
+        <span class="n">event_count</span> <span class="o">=</span> <span class="mi">1</span>
+        <span class="k">while</span> <span class="n">event_count</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="k">if</span> <span class="n">next_token</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
+                <span class="n">token_arg</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;nextToken&#39;</span><span class="p">:</span> <span class="n">next_token</span><span class="p">}</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">token_arg</span> <span class="o">=</span> <span class="p">{}</span>
+
+            <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_log_conn</span><span class="p">()</span><span class="o">.</span><span class="n">get_log_events</span><span class="p">(</span><span class="n">logGroupName</span><span class="o">=</span><span class="n">log_group</span><span class="p">,</span>
+                                                          <span class="n">logStreamName</span><span class="o">=</span><span class="n">stream_name</span><span class="p">,</span>
+                                                          <span class="n">startTime</span><span class="o">=</span><span class="n">start_time</span><span class="p">,</span>
+                                                          <span class="n">startFromHead</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
+                                                          <span class="o">**</span><span class="n">token_arg</span><span class="p">)</span>
+            <span class="n">next_token</span> <span class="o">=</span> <span class="n">response</span><span class="p">[</span><span class="s1">&#39;nextForwardToken&#39;</span><span class="p">]</span>
+            <span class="n">events</span> <span class="o">=</span> <span class="n">response</span><span class="p">[</span><span class="s1">&#39;events&#39;</span><span class="p">]</span>
+            <span class="n">event_count</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">events</span><span class="p">)</span>
+            <span class="k">if</span> <span class="n">event_count</span> <span class="o">&gt;</span> <span class="n">skip</span><span class="p">:</span>
+                <span class="n">events</span> <span class="o">=</span> <span class="n">events</span><span class="p">[</span><span class="n">skip</span><span class="p">:]</span>
+                <span class="n">skip</span> <span class="o">=</span> <span class="mi">0</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">skip</span> <span class="o">=</span> <span class="n">skip</span> <span class="o">-</span> <span class="n">event_count</span>
+                <span class="n">events</span> <span class="o">=</span> <span class="p">[]</span>
+            <span class="k">for</span> <span class="n">ev</span> <span class="ow">in</span> <span class="n">events</span><span class="p">:</span>
+                <span class="k">yield</span> <span class="n">ev</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.multi_stream_iter"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.multi_stream_iter">[docs]</a>    <span class="k">def</span> <span class="nf">multi_stream_iter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">log_group</span><span class="p">,</span> <span class="n">streams</span><span class="p">,</span> <span class="n">positions</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Iterate over the available events coming from a set of log streams in a single log group</span>
+<span class="sd">        interleaving the events from each stream so they&#39;re yielded in timestamp order.</span>
+
+<span class="sd">        :param log_group: The name of the log group.</span>
+<span class="sd">        :type log_group: str</span>
+<span class="sd">        :param streams: A list of the log stream names. The position of the stream in this list is</span>
+<span class="sd">            the stream number.</span>
+<span class="sd">        :type streams: list</span>
+<span class="sd">        :param positions: A list of pairs of (timestamp, skip) which represents the last record</span>
+<span class="sd">            read from each stream.</span>
+<span class="sd">        :type positions: list</span>
+<span class="sd">        :return: A tuple of (stream number, cloudwatch log event).</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">positions</span> <span class="o">=</span> <span class="n">positions</span> <span class="ow">or</span> <span class="p">{</span><span class="n">s</span><span class="p">:</span> <span class="n">Position</span><span class="p">(</span><span class="n">timestamp</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">skip</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">streams</span><span class="p">}</span>
+        <span class="n">event_iters</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">log_stream</span><span class="p">(</span><span class="n">log_group</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">positions</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">timestamp</span><span class="p">,</span> <span class="n">positions</span><span class="p">[</span><span class="n">s</span><span class="p">]</span><span class="o">.</span><span class="n">skip</span><span class="p">)</span>
+                       <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">streams</span><span class="p">]</span>
+        <span class="n">events</span> <span class="o">=</span> <span class="p">[</span><span class="nb">next</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="k">if</span> <span class="n">s</span> <span class="k">else</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">event_iters</span><span class="p">]</span>
+
+        <span class="k">while</span> <span class="nb">any</span><span class="p">(</span><span class="n">events</span><span class="p">):</span>
+            <span class="n">i</span> <span class="o">=</span> <span class="n">argmin</span><span class="p">(</span><span class="n">events</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="s1">&#39;timestamp&#39;</span><span class="p">]</span> <span class="k">if</span> <span class="n">x</span> <span class="k">else</span> <span class="mi">9999999999</span><span class="p">)</span>
+            <span class="k">yield</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">events</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
+            <span class="k">try</span><span class="p">:</span>
+                <span class="n">events</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="nb">next</span><span class="p">(</span><span class="n">event_iters</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
+            <span class="k">except</span> <span class="ne">StopIteration</span><span class="p">:</span>
+                <span class="n">events</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.create_training_job"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.create_training_job">[docs]</a>    <span class="k">def</span> <span class="nf">create_training_job</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">,</span> <span class="n">wait_for_completion</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">print_log</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
+                            <span class="n">check_interval</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">max_ingestion_time</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Create a training job</span>
+
+<span class="sd">        :param config: the config for training</span>
+<span class="sd">        :type config: dict</span>
+<span class="sd">        :param wait_for_completion: if the program should keep running until job finishes</span>
+<span class="sd">        :type wait_for_completion: bool</span>
+<span class="sd">        :param check_interval: the time interval in seconds which the operator</span>
+<span class="sd">            will check the status of any SageMaker job</span>
+<span class="sd">        :type check_interval: int</span>
+<span class="sd">        :param max_ingestion_time: the maximum ingestion time in seconds. Any</span>
+<span class="sd">            SageMaker jobs that run longer than this will fail. Setting this to</span>
+<span class="sd">            None implies no timeout for any SageMaker job.</span>
+<span class="sd">        :type max_ingestion_time: int</span>
+<span class="sd">        :return: A response to training job creation</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">check_training_config</span><span class="p">(</span><span class="n">config</span><span class="p">)</span>
+
+        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">create_training_job</span><span class="p">(</span><span class="o">**</span><span class="n">config</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">print_log</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">check_training_status_with_log</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;TrainingJobName&#39;</span><span class="p">],</span>
+                                                <span class="bp">self</span><span class="o">.</span><span class="n">non_terminal_states</span><span class="p">,</span>
+                                                <span class="bp">self</span><span class="o">.</span><span class="n">failed_states</span><span class="p">,</span>
+                                                <span class="n">wait_for_completion</span><span class="p">,</span>
+                                                <span class="n">check_interval</span><span class="p">,</span> <span class="n">max_ingestion_time</span>
+                                                <span class="p">)</span>
+        <span class="k">elif</span> <span class="n">wait_for_completion</span><span class="p">:</span>
+            <span class="n">describe_response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_status</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;TrainingJobName&#39;</span><span class="p">],</span>
+                                                  <span class="s1">&#39;TrainingJobStatus&#39;</span><span class="p">,</span>
+                                                  <span class="bp">self</span><span class="o">.</span><span class="n">describe_training_job</span><span class="p">,</span>
+                                                  <span class="n">check_interval</span><span class="p">,</span> <span class="n">max_ingestion_time</span>
+                                                  <span class="p">)</span>
+
+            <span class="n">billable_time</span> <span class="o">=</span> \
+                <span class="p">(</span><span class="n">describe_response</span><span class="p">[</span><span class="s1">&#39;TrainingEndTime&#39;</span><span class="p">]</span> <span class="o">-</span> <span class="n">describe_response</span><span class="p">[</span><span class="s1">&#39;TrainingStartTime&#39;</span><span class="p">])</span> <span class="o">*</span> \
+                <span class="n">describe_response</span><span class="p">[</span><span class="s1">&#39;ResourceConfig&#39;</span><span class="p">][</span><span class="s1">&#39;InstanceCount&#39;</span><span class="p">]</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Billable seconds:</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">billable_time</span><span class="o">.</span><span class="n">total_seconds</span><span class="p">())</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>
+
+        <span class="k">return</span> <span class="n">response</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.create_tuning_job"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.create_tuning_job">[docs]</a>    <span class="k">def</span> <span class="nf">create_tuning_job</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">,</span> <span class="n">wait_for_completion</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
+                          <span class="n">check_interval</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">max_ingestion_time</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Create a tuning job</span>
+
+<span class="sd">        :param config: the config for tuning</span>
+<span class="sd">        :type config: dict</span>
+<span class="sd">        :param wait_for_completion: if the program should keep running until job finishes</span>
+<span class="sd">        :param wait_for_completion: bool</span>
+<span class="sd">        :param check_interval: the time interval in seconds which the operator</span>
+<span class="sd">            will check the status of any SageMaker job</span>
+<span class="sd">        :type check_interval: int</span>
+<span class="sd">        :param max_ingestion_time: the maximum ingestion time in seconds. Any</span>
+<span class="sd">            SageMaker jobs that run longer than this will fail. Setting this to</span>
+<span class="sd">            None implies no timeout for any SageMaker job.</span>
+<span class="sd">        :type max_ingestion_time: int</span>
+<span class="sd">        :return: A response to tuning job creation</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">check_tuning_config</span><span class="p">(</span><span class="n">config</span><span class="p">)</span>
+
+        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">create_hyper_parameter_tuning_job</span><span class="p">(</span><span class="o">**</span><span class="n">config</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">wait_for_completion</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">check_status</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;HyperParameterTuningJobName&#39;</span><span class="p">],</span>
+                              <span class="s1">&#39;HyperParameterTuningJobStatus&#39;</span><span class="p">,</span>
+                              <span class="bp">self</span><span class="o">.</span><span class="n">describe_tuning_job</span><span class="p">,</span>
+                              <span class="n">check_interval</span><span class="p">,</span> <span class="n">max_ingestion_time</span>
+                              <span class="p">)</span>
+        <span class="k">return</span> <span class="n">response</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.create_transform_job"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.create_transform_job">[docs]</a>    <span class="k">def</span> <span class="nf">create_transform_job</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">,</span> <span class="n">wait_for_completion</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
+                             <span class="n">check_interval</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">max_ingestion_time</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Create a transform job</span>
+
+<span class="sd">        :param config: the config for transform job</span>
+<span class="sd">        :type config: dict</span>
+<span class="sd">        :param wait_for_completion: if the program should keep running until job finishes</span>
+<span class="sd">        :type wait_for_completion: bool</span>
+<span class="sd">        :param check_interval: the time interval in seconds which the operator</span>
+<span class="sd">            will check the status of any SageMaker job</span>
+<span class="sd">        :type check_interval: int</span>
+<span class="sd">        :param max_ingestion_time: the maximum ingestion time in seconds. Any</span>
+<span class="sd">            SageMaker jobs that run longer than this will fail. Setting this to</span>
+<span class="sd">            None implies no timeout for any SageMaker job.</span>
+<span class="sd">        :type max_ingestion_time: int</span>
+<span class="sd">        :return: A response to transform job creation</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">check_s3_url</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;TransformInput&#39;</span><span class="p">][</span><span class="s1">&#39;DataSource&#39;</span><span class="p">][</span><span class="s1">&#39;S3DataSource&#39;</span><span class="p">][</span><span class="s1">&#39;S3Uri&#39;</span><span class="p">])</span>
+
+        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">create_transform_job</span><span class="p">(</span><span class="o">**</span><span class="n">config</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">wait_for_completion</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">check_status</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;TransformJobName&#39;</span><span class="p">],</span>
+                              <span class="s1">&#39;TransformJobStatus&#39;</span><span class="p">,</span>
+                              <span class="bp">self</span><span class="o">.</span><span class="n">describe_transform_job</span><span class="p">,</span>
+                              <span class="n">check_interval</span><span class="p">,</span> <span class="n">max_ingestion_time</span>
+                              <span class="p">)</span>
+        <span class="k">return</span> <span class="n">response</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.create_model"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.create_model">[docs]</a>    <span class="k">def</span> <span class="nf">create_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Create a model job</span>
+
+<span class="sd">        :param config: the config for model</span>
+<span class="sd">        :type config: dict</span>
+<span class="sd">        :return: A response to model creation</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">create_model</span><span class="p">(</span><span class="o">**</span><span class="n">config</span><span class="p">)</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.create_endpoint_config"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.create_endpoint_config">[docs]</a>    <span class="k">def</span> <span class="nf">create_endpoint_config</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Create an endpoint config</span>
+
+<span class="sd">        :param config: the config for endpoint-config</span>
+<span class="sd">        :type config: dict</span>
+<span class="sd">        :return: A response to endpoint config creation</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">create_endpoint_config</span><span class="p">(</span><span class="o">**</span><span class="n">config</span><span class="p">)</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.create_endpoint"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.create_endpoint">[docs]</a>    <span class="k">def</span> <span class="nf">create_endpoint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">,</span> <span class="n">wait_for_completion</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
+                        <span class="n">check_interval</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">max_ingestion_time</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Create an endpoint</span>
+
+<span class="sd">        :param config: the config for endpoint</span>
+<span class="sd">        :type config: dict</span>
+<span class="sd">        :param wait_for_completion: if the program should keep running until job finishes</span>
+<span class="sd">        :type wait_for_completion: bool</span>
+<span class="sd">        :param check_interval: the time interval in seconds which the operator</span>
+<span class="sd">            will check the status of any SageMaker job</span>
+<span class="sd">        :type check_interval: int</span>
+<span class="sd">        :param max_ingestion_time: the maximum ingestion time in seconds. Any</span>
+<span class="sd">            SageMaker jobs that run longer than this will fail. Setting this to</span>
+<span class="sd">            None implies no timeout for any SageMaker job.</span>
+<span class="sd">        :type max_ingestion_time: int</span>
+<span class="sd">        :return: A response to endpoint creation</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">create_endpoint</span><span class="p">(</span><span class="o">**</span><span class="n">config</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">wait_for_completion</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">check_status</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;EndpointName&#39;</span><span class="p">],</span>
+                              <span class="s1">&#39;EndpointStatus&#39;</span><span class="p">,</span>
+                              <span class="bp">self</span><span class="o">.</span><span class="n">describe_endpoint</span><span class="p">,</span>
+                              <span class="n">check_interval</span><span class="p">,</span> <span class="n">max_ingestion_time</span><span class="p">,</span>
+                              <span class="n">non_terminal_states</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">endpoint_non_terminal_states</span>
+                              <span class="p">)</span>
+        <span class="k">return</span> <span class="n">response</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.update_endpoint"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.update_endpoint">[docs]</a>    <span class="k">def</span> <span class="nf">update_endpoint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">,</span> <span class="n">wait_for_completion</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
+                        <span class="n">check_interval</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">max_ingestion_time</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Update an endpoint</span>
+
+<span class="sd">        :param config: the config for endpoint</span>
+<span class="sd">        :type config: dict</span>
+<span class="sd">        :param wait_for_completion: if the program should keep running until job finishes</span>
+<span class="sd">        :type wait_for_completion: bool</span>
+<span class="sd">        :param check_interval: the time interval in seconds which the operator</span>
+<span class="sd">            will check the status of any SageMaker job</span>
+<span class="sd">        :type check_interval: int</span>
+<span class="sd">        :param max_ingestion_time: the maximum ingestion time in seconds. Any</span>
+<span class="sd">            SageMaker jobs that run longer than this will fail. Setting this to</span>
+<span class="sd">            None implies no timeout for any SageMaker job.</span>
+<span class="sd">        :type max_ingestion_time: int</span>
+<span class="sd">        :return: A response to endpoint update</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">update_endpoint</span><span class="p">(</span><span class="o">**</span><span class="n">config</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">wait_for_completion</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">check_status</span><span class="p">(</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;EndpointName&#39;</span><span class="p">],</span>
+                              <span class="s1">&#39;EndpointStatus&#39;</span><span class="p">,</span>
+                              <span class="bp">self</span><span class="o">.</span><span class="n">describe_endpoint</span><span class="p">,</span>
+                              <span class="n">check_interval</span><span class="p">,</span> <span class="n">max_ingestion_time</span><span class="p">,</span>
+                              <span class="n">non_terminal_states</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">endpoint_non_terminal_states</span>
+                              <span class="p">)</span>
+        <span class="k">return</span> <span class="n">response</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.describe_training_job"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.describe_training_job">[docs]</a>    <span class="k">def</span> <span class="nf">describe_training_job</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Return the training job info associated with the name</span>
+
+<span class="sd">        :param name: the name of the training job</span>
+<span class="sd">        :type name: str</span>
+<span class="sd">        :return: A dict contains all the training job info</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">describe_training_job</span><span class="p">(</span><span class="n">TrainingJobName</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.describe_training_job_with_log"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.describe_training_job_with_log">[docs]</a>    <span class="k">def</span> <span class="nf">describe_training_job_with_log</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">job_name</span><span class="p">,</span> <span class="n">positions</span><span class="p">,</span> <span class="n">stream_names</span><span class="p">,</span>
+                                       <span class="n">instance_count</span><span class="p">,</span> <span class="n">state</span><span class="p">,</span> <span class="n">last_description</span><span class="p">,</span>
+                                       <span class="n">last_describe_job_call</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Return the training job info associated with job_name and print CloudWatch logs</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="n">log_group</span> <span class="o">=</span> <span class="s1">&#39;/aws/sagemaker/TrainingJobs&#39;</span>
+
+        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">stream_names</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">instance_count</span><span class="p">:</span>
+            <span class="c1"># Log streams are created whenever a container starts writing to stdout/err, so this list</span>
+            <span class="c1"># may be dynamic until we have a stream for every instance.</span>
+            <span class="n">logs_conn</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_log_conn</span><span class="p">()</span>
+            <span class="k">try</span><span class="p">:</span>
+                <span class="n">streams</span> <span class="o">=</span> <span class="n">logs_conn</span><span class="o">.</span><span class="n">describe_log_streams</span><span class="p">(</span>
+                    <span class="n">logGroupName</span><span class="o">=</span><span class="n">log_group</span><span class="p">,</span>
+                    <span class="n">logStreamNamePrefix</span><span class="o">=</span><span class="n">job_name</span> <span class="o">+</span> <span class="s1">&#39;/&#39;</span><span class="p">,</span>
+                    <span class="n">orderBy</span><span class="o">=</span><span class="s1">&#39;LogStreamName&#39;</span><span class="p">,</span>
+                    <span class="n">limit</span><span class="o">=</span><span class="n">instance_count</span>
+                <span class="p">)</span>
+                <span class="n">stream_names</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="p">[</span><span class="s1">&#39;logStreamName&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">streams</span><span class="p">[</span><span class="s1">&#39;logStreams&#39;</span><span class="p">]]</span>
+                <span class="n">positions</span><span class="o">.</span><span class="n">update</span><span class="p">([(</span><span class="n">s</span><span class="p">,</span> <span class="n">Position</span><span class="p">(</span><span class="n">timestamp</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">skip</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span>
+                                  <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">stream_names</span> <span class="k">if</span> <span class="n">s</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">positions</span><span class="p">])</span>
+            <span class="k">except</span> <span class="n">logs_conn</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">ResourceNotFoundException</span><span class="p">:</span>
+                <span class="c1"># On the very first training job run on an account, there&#39;s no log group until</span>
+                <span class="c1"># the container starts logging, so ignore any errors thrown about that</span>
+                <span class="k">pass</span>
+
+        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">stream_names</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">event</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">multi_stream_iter</span><span class="p">(</span><span class="n">log_group</span><span class="p">,</span> <span class="n">stream_names</span><span class="p">,</span> <span class="n">positions</span><span class="p">):</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">event</span><span class="p">[</span><span class="s1">&#39;message&#39;</span><span class="p">])</span>
+                <span class="n">ts</span><span class="p">,</span> <span class="n">count</span> <span class="o">=</span> <span class="n">positions</span><span class="p">[</span><span class="n">stream_names</span><span class="p">[</span><span class="n">idx</span><span class="p">]]</span>
+                <span class="k">if</span> <span class="n">event</span><span class="p">[</span><span class="s1">&#39;timestamp&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="n">ts</span><span class="p">:</span>
+                    <span class="n">positions</span><span class="p">[</span><span class="n">stream_names</span><span class="p">[</span><span class="n">idx</span><span class="p">]]</span> <span class="o">=</span> <span class="n">Position</span><span class="p">(</span><span class="n">timestamp</span><span class="o">=</span><span class="n">ts</span><span class="p">,</span> <span class="n">skip</span><span class="o">=</span><span class="n">count</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
+                <span class="k">else</span><span class="p">:</span>
+                    <span class="n">positions</span><span class="p">[</span><span class="n">stream_names</span><span class="p">[</span><span class="n">idx</span><span class="p">]]</span> <span class="o">=</span> <span class="n">Position</span><span class="p">(</span><span class="n">timestamp</span><span class="o">=</span><span class="n">event</span><span class="p">[</span><span class="s1">&#39;timestamp&#39;</span><span class="p">],</span> <span class="n">skip</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="n">state</span> <span class="o">==</span> <span class="n">LogState</span><span class="o">.</span><span class="n">COMPLETE</span><span class="p">:</span>
+            <span class="k">return</span> <span class="n">state</span><span class="p">,</span> <span class="n">last_description</span><span class="p">,</span> <span class="n">last_describe_job_call</span>
+
+        <span class="k">if</span> <span class="n">state</span> <span class="o">==</span> <span class="n">LogState</span><span class="o">.</span><span class="n">JOB_COMPLETE</span><span class="p">:</span>
+            <span class="n">state</span> <span class="o">=</span> <span class="n">LogState</span><span class="o">.</span><span class="n">COMPLETE</span>
+        <span class="k">elif</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">last_describe_job_call</span> <span class="o">&gt;=</span> <span class="mi">30</span><span class="p">:</span>
+            <span class="n">description</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">describe_training_job</span><span class="p">(</span><span class="n">job_name</span><span class="p">)</span>
+            <span class="n">last_describe_job_call</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
+
+            <span class="k">if</span> <span class="n">secondary_training_status_changed</span><span class="p">(</span><span class="n">description</span><span class="p">,</span> <span class="n">last_description</span><span class="p">):</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">secondary_training_status_message</span><span class="p">(</span><span class="n">description</span><span class="p">,</span> <span class="n">last_description</span><span class="p">))</span>
+                <span class="n">last_description</span> <span class="o">=</span> <span class="n">description</span>
+
+            <span class="n">status</span> <span class="o">=</span> <span class="n">description</span><span class="p">[</span><span class="s1">&#39;TrainingJobStatus&#39;</span><span class="p">]</span>
+
+            <span class="k">if</span> <span class="n">status</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">non_terminal_states</span><span class="p">:</span>
+                <span class="n">state</span> <span class="o">=</span> <span class="n">LogState</span><span class="o">.</span><span class="n">JOB_COMPLETE</span>
+        <span class="k">return</span> <span class="n">state</span><span class="p">,</span> <span class="n">last_description</span><span class="p">,</span> <span class="n">last_describe_job_call</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.describe_tuning_job"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.describe_tuning_job">[docs]</a>    <span class="k">def</span> <span class="nf">describe_tuning_job</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Return the tuning job info associated with the name</span>
+
+<span class="sd">        :param name: the name of the tuning job</span>
+<span class="sd">        :type name: string</span>
+<span class="sd">        :return: A dict contains all the tuning job info</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">describe_hyper_parameter_tuning_job</span><span class="p">(</span><span class="n">HyperParameterTuningJobName</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.describe_model"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.describe_model">[docs]</a>    <span class="k">def</span> <span class="nf">describe_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Return the SageMaker model info associated with the name</span>
+
+<span class="sd">        :param name: the name of the SageMaker model</span>
+<span class="sd">        :type name: string</span>
+<span class="sd">        :return: A dict contains all the model info</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">describe_model</span><span class="p">(</span><span class="n">ModelName</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.describe_transform_job"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.describe_transform_job">[docs]</a>    <span class="k">def</span> <span class="nf">describe_transform_job</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Return the transform job info associated with the name</span>
+
+<span class="sd">        :param name: the name of the transform job</span>
+<span class="sd">        :type name: string</span>
+<span class="sd">        :return: A dict contains all the transform job info</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">describe_transform_job</span><span class="p">(</span><span class="n">TransformJobName</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.describe_endpoint_config"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.describe_endpoint_config">[docs]</a>    <span class="k">def</span> <span class="nf">describe_endpoint_config</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Return the endpoint config info associated with the name</span>
+
+<span class="sd">        :param name: the name of the endpoint config</span>
+<span class="sd">        :type name: string</span>
+<span class="sd">        :return: A dict contains all the endpoint config info</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">describe_endpoint_config</span><span class="p">(</span><span class="n">EndpointConfigName</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.describe_endpoint"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.describe_endpoint">[docs]</a>    <span class="k">def</span> <span class="nf">describe_endpoint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        :param name: the name of the endpoint</span>
+<span class="sd">        :type name: string</span>
+<span class="sd">        :return: A dict contains all the endpoint info</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+
+        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span><span class="o">.</span><span class="n">describe_endpoint</span><span class="p">(</span><span class="n">EndpointName</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></div>
+
+<div class="viewcode-block" id="SageMakerHook.check_status"><a class="viewcode-back" href="../../../../code.html#airflow.contrib.hooks.sagemaker_hook.SageMakerHook.check_status">[docs]</a>    <span class="k">def</span> <span class="nf">check_status</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">job_name</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span>
+                     <span class="n">describe_function</span><span class="p">,</span> <span class="n">check_interval</span><span class="p">,</span>
+                     <span class="n">max_ingestion_time</span><span class="p">,</span>
+                     <span class="n">non_terminal_states</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Check status of a SageMaker job</span>
+
+<span class="sd">        :param job_name: name of the job to check status</span>
+<span class="sd">        :type job_name: str</span>
+<span class="sd">        :param key: the key of the response dict</span>
+<span class="sd">            that points to the state</span>
+<span class="sd">        :type key: str</span>
+<span class="sd">        :param describe_function: the function used to retrieve the status</span>
+<span class="sd">        :type describe_function: py

<TRUNCATED>


Mime
View raw message