Repository: serverless-heaven/serverless-webpack (js)
Issue: aws-sdk: warning on deployment


# This is a Bug Report

## Description

Updated webpack serverless and now get warning when deploying

```
Serverless: WARNING: Runtime dependency 'aws-sdk' found in devDependencies. You should use forceExclude to explicitly exclude it.
```

Config:
```
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const Dotenv = require('dotenv-webpack');

module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  // Generate sourcemaps for proper error messages
  devtool: 'source-map',
  // Since 'aws-sdk' is not compatible with webpack,
  // we exclude all node dependencies
  externals: [nodeExternals()],
  mode: slsw.lib.webpack.isLocal
    ? 'development'
    : 'production',
  optimization: {
    // We no not want to minimize our code.
    minimize: false
  },
  performance: {
    // Turn off size warnings for entry points
    hints: false
  },
  plugins: [new Dotenv()],
  // Run babel on all .js files and skip those in node_modules
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: __dirname,
        exclude: /node_modules/
      }
    ]
  }
};

```




Similar or dependent issue(s):


## Additional Data

* ***Serverless-Webpack Version you're using***: 5.1.5
* ***Webpack version you're using***: 4.8.3
* ***Serverless Framework Version you're using***: 1.27.2
* ***Operating System***: linux
* ***Stack Trace (if available)***:

Pull request description: Updated docs and message for aws-sdk dependency exclusion
<!--
1. Do not remove any section of the template. If something is not applicable leave it empty but leave it in the PR
2. Please follow the template, otherwise we'll have to ask you to update it and it will take longer until your PR is merged
-->

## What did you implement:

Closes #393 

Added paragraph to the README that explains the improved dependency validation.
Changed aws-sdk warning to informational message shown only with `--verbose`

<!--
Briefly describe the feature if no issue exists for this PR. If possible only
submit PRs for existing issues. If the PR is trivial (like doc changes or simple
code fixes) it can be submitted without a related issue, but as soon as it adds
or changes functionality, a related issue should be present.
-->

## How did you implement it:

<!--
If this is a nontrivial change please briefly describe your implementation so its easy for us to understand and review your code.
-->

## How can we verify it:

<!--
Add any applicable config, commands, screenshots or other resources
to make it easy for us to verify this works. The easier you make it for us
to review a PR, the faster we can review and merge it.

Examples:
* Step by step description, how to verify
* Screenshots - Showing the difference between your output and the master
* Other - Anything else that comes to mind to help us evaluate
-->

## Todos:

- ~~Write tests~~
- [x] Write documentation
- ~~Fix linting errors~~
- ~~Make sure code coverage hasn't dropped~~
- ~~Provide verification config / commands / resources~~
- [x] Enable "Allow edits from maintainers" for this PR
- [x] Update the messages below

***Is this ready for review?:*** YES
***Is it a breaking change?:*** NO


Patch:
diff --git a/README.md b/README.md
index 5beedc0..8400ace 100644
--- a/README.md
+++ b/README.md
@@ -247,6 +247,31 @@ custom:
 ```
 > Note that only relative path is supported at the moment.
 
+#### Runtime dependencies
+
+If a runtime dependency is detected that is found in the `devDependencies` section and
+so would not be packaged, the plugin will error until you explicitly exclude it (see `forceExclude` below) 
+or move it to the `dependencies` section.
+
+#### AWS-SDK
+
+An exception for the runtime dependency error is the AWS-SDK. All projects using the AWS-SDK normally
+have it listed in `devDependencies` because AWS provides it already in their Lambda environment. In this case 
+the aws-sdk is automatically excluded and only an informational message is printed (in `--verbose` mode).
+
+The main reason for the warning is, that silently ignoring anything contradicts the declarative nature
+of Serverless' service definition. So the correct way to define the handling for the aws-sdk is, as 
+you would do for all other excluded modules (see `forceExclude` below).
+
+```yaml
+# serverless.yml
+custom:
+  webpack:
+    includeModules:
+      forceExclude:
+        - aws-sdk
+```
+
 #### Packagers
 
 You can select the packager that will be used to package your external modules.
diff --git a/lib/packExternalModules.js b/lib/packExternalModules.js
index 35487c4..6b1fc9e 100644
--- a/lib/packExternalModules.js
+++ b/lib/packExternalModules.js
@@ -115,7 +115,7 @@ function getProdModules(externalModules, packagePath, dependencyGraph, forceExcl
           throw new this.serverless.classes.Error(`Serverless-webpack dependency error: ${module.external}.`);
         }
 
-        this.serverless.cli.log(`WARNING: Runtime dependency '${module.external}' found in devDependencies. You should use forceExclude to explicitly exclude it.`);
+        this.options.verbose && this.serverless.cli.log(`INFO: Runtime dependency '${module.external}' found in devDependencies. It has been excluded automatically.`);
       }
     }
   });


Test patch:
diff --git a/tests/packExternalModules.test.js b/tests/packExternalModules.test.js
index c872514..7eebd55 100644
--- a/tests/packExternalModules.test.js
+++ b/tests/packExternalModules.test.js
@@ -878,7 +878,7 @@ describe('packExternalModules', () => {
       mockery.registerMock(path.join(process.cwd(), 'ignoreDevDeps', 'package.json'), packageIgnoredDevDepsMock);
       return expect(module.packExternalModules()).to.be.fulfilled
       .then(() => BbPromise.all([
-        expect(module.serverless.cli.log).to.have.been.calledWith(sinon.match(/WARNING: Runtime dependency 'aws-sdk' found in devDependencies/)),
+        expect(module.serverless.cli.log).to.have.been.calledWith(sinon.match(/INFO: Runtime dependency 'aws-sdk' found in devDependencies/)),
         // npm ls and npm install should have been called
         expect(packagerMock.getProdDependencies).to.have.been.calledOnce,
         expect(packagerMock.install).to.have.been.calledOnce,