title: Lambda function to shutdown RDS not working - NameError: name 'client' is not defined
body: <p>I am using the below Lambda function but keep getting errors. I was able to use the function at the <em>bottom</em> of this page via Pycharm conducting some tests so was expecting this to work in Lambda. Any help would be greatly appreciated.</p>
  <pre><code>import boto3
  
  def handler(event, context):
      client = boto3.client('rds')
  
  response = client.stop_db_instance(
      DBInstanceIdentifier='dev-mysql-rds'
  )
  </code></pre>
  <blockquote>
  <p>Response: {   &quot;errorMessage&quot;: &quot;name 'client' is not defined&quot;,<br />
  &quot;errorType&quot;: &quot;NameError&quot;,   &quot;stackTrace&quot;: [
  &quot;  File &quot;/var/lang/lib/python3.8/imp.py&quot;, line 234, in load_module\n    return load_source(name, filename, file)\n&quot;,
  &quot;  File &quot;/var/lang/lib/python3.8/imp.py&quot;, line 171, in load_source\n    module = _load(spec)\n&quot;,
  &quot;  File &quot;&quot;, line 702, in _load\n&quot;,
  &quot;  File &quot;&quot;, line 671, in _load_unlocked\n&quot;,
  &quot;  File &quot;&quot;, line 783, in exec_module\n&quot;,
  &quot;  File &quot;&quot;, line 219, in _call_with_frames_removed\n&quot;,
  &quot;  File &quot;/var/task/lambda_function.py&quot;, line 6, in \n    response = client.stop_db_instance(\n&quot;   ] }</p>
  <p>Request ID: &quot;7fd994c0-799f-44a2-b93f-a437fee740af&quot;</p>
  <p>Function logs: START RequestId: 7fd994c0-799f-44a2-b93f-a437fee740af
  Version: $LATEST [ERROR] NameError: name 'client' is not defined
  Traceback (most recent call last):   File
  &quot;/var/lang/lib/python3.8/imp.py&quot;, line 234, in load_module
      return load_source(name, filename, file)   File &quot;/var/lang/lib/python3.8/imp.py&quot;, line 171, in load_source
      module = _load(spec)   File &quot;&quot;, line 702, in _load   File &quot;&quot;, line 671, in
  _load_unlocked   File &quot;&quot;, line 783, in exec_module   File &quot;&quot;, line 219,
  in _call_with_frames_removed   File &quot;/var/task/lambda_function.py&quot;,
  line 6, in 
      response = client.stop_db_instance(END RequestId: 7fd994c0-799f-44a2-b93f-a437fee740af REPORT RequestId:
  7fd994c0-799f-44a2-b93f-a437fee740af  Duration: 352.02 ms Billed
  Duration: 353 ms  Memory Size: 1024 MB    Max Memory Used: 22 MB   Unknown
  application error occurred</p>
  </blockquote>
  <p><strong>The below function works via Pycharm.</strong></p>
  <pre><code>import boto3
  rds = boto3.setup_default_session(profile_name='dev')
  client = boto3.client('rds')
  
  response = client.stop_db_instance(
      DBInstanceIdentifier='dev-mysql-rds'
  )
  </code></pre>