Repository: serverless/serverless (JavaScript) — Bug Fix

Issue:
1.48.1 gives Credentials error.
<!--
1. If you have a question and not a bug report please ask first at http://forum.serverless.com
2. Please check if an issue already exists. This bug may have already been documented
3. Check out and follow our Guidelines: https://github.com/serverless/serverless/blob/master/CONTRIBUTING.md
4. Fill out the whole template so we have a good overview on the issue
5. Do not remove any section of the template. If something is not applicable leave it empty but leave it in the Issue
6. Please follow the template, otherwise we'll have to ask you to update it
-->

# This is a Bug Report

## Description

- What went wrong?

    - Get this error now when deploying through an AWS pipeline: 
```
Serverless Error --------------------------------------- 
  
Could not locate deployment bucket. Error: AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://bit.ly/aws-creds-setup>.
```
Our set up uses a serverless.yml file to deploy stacks. The pipeline were successfully building before the release of 1.48.1. I verified that this was an issue with serverless by installing 1.48.0 instead of the latest release using this command: `npm install -g serverless@1.48.0`. When I use 1.48.0 the builds pass as expected. 
- What did you expect should have happened?
     - I expected the build to pass 
- What was the config you used?
- What stacktrace or error message from your provider did you see?

Similar or dependent issues:

- #12345

## Additional Data

- **_Serverless Framework Version you're using_**: 1.48.1
- **_Operating System_**:
- **_Stack Trace_**:
- **_Provider Error messages_**:

1.48.1 gives Credentials error.
<!--
1. If you have a question and not a bug report please ask first at http://forum.serverless.com
2. Please check if an issue already exists. This bug may have already been documented
3. Check out and follow our Guidelines: https://github.com/serverless/serverless/blob/master/CONTRIBUTING.md
4. Fill out the whole template so we have a good overview on the issue
5. Do not remove any section of the template. If something is not applicable leave it empty but leave it in the Issue
6. Please follow the template, otherwise we'll have to ask you to update it
-->

# This is a Bug Report

## Description

- What went wrong?

    - Get this error now when deploying through an AWS pipeline: 
```
Serverless Error --------------------------------------- 
  
Could not locate deployment bucket. Error: AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://bit.ly/aws-creds-setup>.
```
Our set up uses a serverless.yml file to deploy stacks. The pipeline were successfully building before the release of 1.48.1. I verified that this was an issue with serverless by installing 1.48.0 instead of the latest release using this command: `npm install -g serverless@1.48.0`. When I use 1.48.0 the builds pass as expected. 
- What did you expect should have happened?
     - I expected the build to pass 
- What was the config you used?
- What stacktrace or error message from your provider did you see?

Similar or dependent issues:

- #12345

## Additional Data

- **_Serverless Framework Version you're using_**: 1.48.1
- **_Operating System_**:
- **_Stack Trace_**:
- **_Provider Error messages_**:



Discussion:
I am having the same issue
What ever changes you merged onto `master` caused my CodePipeline to break also, as I have the same error. Im rolling back to 1.48 in my BuildSpec.yml for the time being but I would like to figure out what's going on here so I can update my environment when possible. Thanks!

`ServerlessError: AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://bit.ly/aws-creds-setup>. `
Same issue when trying to deploy in AWS CodePipeline.
Piece of log:
```Serverless: Packaging service... 
Serverless: Excluding development dependencies... 
Serverless: Excluding development dependencies... 
Serverless: Excluding development dependencies... 
Serverless: Excluding development dependencies... 
Serverless: Excluding development dependencies... 
Serverless: Excluding development dependencies... 
Serverless:  
User stats error: Request network error: { FetchError: network timeout at: https://tracking.serverlessteam.com/v1/track 
    at Timeout._onTimeout (/usr/local/lib/node_modules/serverless/node_modules/node-fetch/index.js:126:13) 
    at ontimeout (timers.js:436:11) 
    at tryOnTimeout (timers.js:300:5) 
    at listOnTimeout (timers.js:263:5) 
    at Timer.processTimers (timers.js:223:10) 
  name: 'FetchError', 
  message: 
   'network timeout at: https://tracking.serverlessteam.com/v1/track', 
  type: 'request-timeout' } 
Serverless: Invoke aws:package:finalize 
Serverless: Invoke aws:common:moveArtifactsToPackage 
Serverless: Invoke aws:common:validate 
Serverless: Invoke aws:deploy:deploy 
  
  Serverless Error --------------------------------------- 
  
  ServerlessError: AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://bit.ly/aws-creds-setup>. 
  
  Stack Trace -------------------------------------------- 
  
ServerlessError: ServerlessError: AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://bit.ly/aws-creds-setup>. 
    at AwsDeploy.BbPromise.bind.then.catch.e (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/lib/createStack.js:91:15) 
From previous event: 
    at AwsDeploy.createStack (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/lib/createStack.js:83:13) 
From previous event: 
    at Object.aws:deploy:deploy:createStack [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:99:67) 
    at BbPromise.reduce (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:464:55) 
From previous event: 
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:464:22) 
    at PluginManager.spawn (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:484:17) 
    at AwsDeploy.BbPromise.bind.then (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:93:48) 
From previous event: 
    at Object.deploy:deploy [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:89:30) 
    at BbPromise.reduce (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:464:55) 
From previous event: 
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:464:22) 
    at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:496:17) 
    at variables.populateService.then (/usr/local/lib/node_modules/serverless/lib/Serverless.js:116:33) 
    at runCallback (timers.js:705:18) 
    at tryOnImmediate (timers.js:676:5) 
    at processImmediate (timers.js:658:5) 
    at process.topLevelDomainCallback (domain.js:126:23) 
From previous event: 
    at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:103:74) 
    at serverless.init.then (/usr/local/lib/node_modules/serverless/bin/serverless.js:52:28) 
    at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:111:16 
    at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:45:10 
    at FSReqWrap.args [as oncomplete] (fs.js:140:20) 
From previous event: 
    at initializeErrorReporter.then (/usr/local/lib/node_modules/serverless/bin/serverless.js:52:6) 
    at runCallback (timers.js:705:18) 
    at tryOnImmediate (timers.js:676:5) 
    at processImmediate (timers.js:658:5) 
    at process.topLevelDomainCallback (domain.js:126:23) 
From previous event: 
    at Object.<anonymous> (/usr/local/lib/node_modules/serverless/bin/serverless.js:38:39) 
    at Module._compile (internal/modules/cjs/loader.js:776:30) 
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) 
    at Module.load (internal/modules/cjs/loader.js:653:32) 
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12) 
    at Function.Module._load (internal/modules/cjs/loader.js:585:3) 
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12) 
    at startup (internal/bootstrap/node.js:283:19) 
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3) 
  
  Get Support -------------------------------------------- 
     Docs:          docs.serverless.com 
     Bugs:          github.com/serverless/serverless/issues 
     Issues:        forum.serverless.com 
  
  Your Environment Information --------------------------- 
     Operating System:          linux 
     Node Version:              10.16.0 
     Serverless Version:        1.48.2 
     Enterprise Plugin Version: 1.3.1 
     Platform SDK Version:      2.0.3 ```
Still facing the same issue with 1.48.1, had to restore back to 1.48.0 in BuildSpec.yml.
Hey @ryryfasch, thanks for opening this issue and thanks everyone for chiming in.

Apparently this PR broke causes the problem: https://github.com/serverless/serverless/pull/6393

It seems like all of you use CodePipeline, so my hunch is that there's something going on with the credentials in the CI / CD environment. Can anyone shed some light into the way CodePipeline handles AWS credentials to carry out the deployments? With that information we can provide a fix ASAP. Thanks!

  
  Serverless Error --------------------------------------- 
  
  ServerlessError: AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://bit.ly/aws-creds-setup>. 
  
  Get Support -------------------------------------------- 
     Docs:          docs.serverless.com 
     Bugs:          github.com/serverless/serverless/issues 
     Issues:        forum.serverless.com 
  
  Your Environment Information --------------------------- 
     Operating System:          linux 
     Node Version:              10.16.0 
     Serverless Version:        1.48.2 
     Enterprise Plugin Version: 1.3.1 
     Platform SDK Version:      2.0.3 

Had the same problem in codebuild stage in codepipeline. Serveless doesn't seem to be able to get the role associated with the codebuild instance. 

Went back to 1.48.0 and everything is working. 
+1 on AWS CodeBuild. Rolled back to 1.48.0 for now.

Serverless Error --------------------------------------- 
  
  ServerlessError: AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://bit.ly/aws-creds-setup>. 
  
  Get Support -------------------------------------------- 
     Docs:          docs.serverless.com 
     Bugs:          github.com/serverless/serverless/issues 
     Issues:        forum.serverless.com 
  
  Your Environment Information --------------------------- 
     Operating System:          linux 
     Node Version:              10.16.0 
     Serverless Version:        1.48.2 
     Enterprise Plugin Version: 1.3.1 
     Platform SDK Version:      2.0.3 
@pmuens I believe CodeBuild sets environment variables for AWS credentials based on the configured pipeline role.

The variables in question should be:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_SESSION_TOKEN

I'm guessing serverless isn't falling back to these environment variables anymore when looking for credentials.
It's also not falling back to the metadata API.  That's the mech that I've used by default. I'll comment on the PR and see if I can work out what broke.
Ok, so PR #6393 implies that you'll have a default profile and some credentials set.  That's not the case, as AWS falls back to metadata API and the IAM role of the machine executing.  I guess that's the case with CodePipeline too (uses IAM attached to the job to set permissions).
Hmm. @dci-aloughran I attempted to check the creds in #6427 using `AWS.EC2MetadataCredentials` but to no avail 😖 
Ahah, per https://docs.aws.amazon.com/codebuild/latest/userguide/troubleshooting.html#troubleshooting-versions CodeBuild uses `AWS.RemoteCredentials`, gonna try that.
I am having the same issue
What ever changes you merged onto `master` caused my CodePipeline to break also, as I have the same error. Im rolling back to 1.48 in my BuildSpec.yml for the time being but I would like to figure out what's going on here so I can update my environment when possible. Thanks!

`ServerlessError: AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://bit.ly/aws-creds-setup>. `
Same issue when trying to deploy in AWS CodePipeline.
Piece of log:
```Serverless: Packaging service... 
Serverless: Excluding development dependencies... 
Serverless: Excluding development dependencies... 
Serverless: Excluding development dependencies... 
Serverless: Excluding development dependencies... 
Serverless: Excluding development dependencies... 
Serverless: Excluding development dependencies... 
Serverless:  
User stats error: Request network error: { FetchError: network timeout at: https://tracking.serverlessteam.com/v1/track 
    at Timeout._onTimeout (/usr/local/lib/node_modules/serverless/node_modules/node-fetch/index.js:126:13) 
    at ontimeout (timers.js:436:11) 
    at tryOnTimeout (timers.js:300:5) 
    at listOnTimeout (timers.js:263:5) 
    at Timer.processTimers (timers.js:223:10) 
  name: 'FetchError', 
  message: 
   'network timeout at: https://tracking.serverlessteam.com/v1/track', 
  type: 'request-timeout' } 
Serverless: Invoke aws:package:finalize 
Serverless: Invoke aws:common:moveArtifactsToPackage 
Serverless: Invoke aws:common:validate 
Serverless: Invoke aws:deploy:deploy 
  
  Serverless Error --------------------------------------- 
  
  ServerlessError: AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://bit.ly/aws-creds-setup>. 
  
  Stack Trace -------------------------------------------- 
  
ServerlessError: ServerlessError: AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://bit.ly/aws-creds-setup>. 
    at AwsDeploy.BbPromise.bind.then.catch.e (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/lib/createStack.js:91:15) 
From previous event: 
    at AwsDeploy.createStack (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/lib/createStack.js:83:13) 
From previous event: 
    at Object.aws:deploy:deploy:createStack [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:99:67) 
    at BbPromise.reduce (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:464:55) 
From previous event: 
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:464:22) 
    at PluginManager.spawn (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:484:17) 
    at AwsDeploy.BbPromise.bind.then (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:93:48) 
From previous event: 
    at Object.deploy:deploy [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:89:30) 
    at BbPromise.reduce (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:464:55) 
From previous event: 
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:464:22) 
    at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:496:17) 
    at variables.populateService.then (/usr/local/lib/node_modules/serverless/lib/Serverless.js:116:33) 
    at runCallback (timers.js:705:18) 
    at tryOnImmediate (timers.js:676:5) 
    at processImmediate (timers.js:658:5) 
    at process.topLevelDomainCallback (domain.js:126:23) 
From previous event: 
    at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:103:74) 
    at serverless.init.then (/usr/local/lib/node_modules/serverless/bin/serverless.js:52:28) 
    at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:111:16 
    at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:45:10 
    at FSReqWrap.args [as oncomplete] (fs.js:140:20) 
From previous event: 
    at initializeErrorReporter.then (/usr/local/lib/node_modules/serverless/bin/serverless.js:52:6) 
    at runCallback (timers.js:705:18) 
    at tryOnImmediate (timers.js:676:5) 
    at processImmediate (timers.js:658:5) 
    at process.topLevelDomainCallback (domain.js:126:23) 
From previous event: 
    at Object.<anonymous> (/usr/local/lib/node_modules/serverless/bin/serverless.js:38:39) 
    at Module._compile (internal/modules/cjs/loader.js:776:30) 
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) 
    at Module.load (internal/modules/cjs/loader.js:653:32) 
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12) 
    at Function.Module._load (internal/modules/cjs/loader.js:585:3) 
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12) 
    at startup (internal/bootstrap/node.js:283:19) 
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3) 
  
  Get Support -------------------------------------------- 
     Docs:          docs.serverless.com 
     Bugs:          github.com/serverless/serverless/issues 
     Issues:        forum.serverless.com 
  
  Your Environment Information --------------------------- 
     Operating System:          linux 
     Node Version:              10.16.0 
     Serverless Version:        1.48.2 
     Enterprise Plugin Version: 1.3.1 
     Platform SDK Version:      2.0.3 ```
Still facing the same issue with 1.48.1, had to restore back to 1.48.0 in BuildSpec.yml.
Hey @ryryfasch, thanks for opening this issue and thanks everyone for chiming in.

Apparently this PR broke causes the problem: https://github.com/serverless/serverless/pull/6393

It seems like all of you use CodePipeline, so my hunch is that there's something going on with the credentials in the CI / CD environment. Can anyone shed some light into the way CodePipeline handles AWS credentials to carry out the deployments? With that information we can provide a fix ASAP. Thanks!

  
  Serverless Error --------------------------------------- 
  
  ServerlessError: AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://bit.ly/aws-creds-setup>. 
  
  Get Support -------------------------------------------- 
     Docs:          docs.serverless.com 
     Bugs:          github.com/serverless/serverless/issues 
     Issues:        forum.serverless.com 
  
  Your Environment Information --------------------------- 
     Operating System:          linux 
     Node Version:              10.16.0 
     Serverless Version:        1.48.2 
     Enterprise Plugin Version: 1.3.1 
     Platform SDK Version:      2.0.3 

Had the same problem in codebuild stage in codepipeline. Serveless doesn't seem to be able to get the role associated with the codebuild instance. 

Went back to 1.48.0 and everything is working. 
+1 on AWS CodeBuild. Rolled back to 1.48.0 for now.

Serverless Error --------------------------------------- 
  
  ServerlessError: AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://bit.ly/aws-creds-setup>. 
  
  Get Support -------------------------------------------- 
     Docs:          docs.serverless.com 
     Bugs:          github.com/serverless/serverless/issues 
     Issues:        forum.serverless.com 
  
  Your Environment Information --------------------------- 
     Operating System:          linux 
     Node Version:              10.16.0 
     Serverless Version:        1.48.2 
     Enterprise Plugin Version: 1.3.1 
     Platform SDK Version:      2.0.3 
@pmuens I believe CodeBuild sets environment variables for AWS credentials based on the configured pipeline role.

The variables in question should be:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_SESSION_TOKEN

I'm guessing serverless isn't falling back to these environment variables anymore when looking for credentials.
It's also not falling back to the metadata API.  That's the mech that I've used by default. I'll comment on the PR and see if I can work out what broke.
Ok, so PR #6393 implies that you'll have a default profile and some credentials set.  That's not the case, as AWS falls back to metadata API and the IAM role of the machine executing.  I guess that's the case with CodePipeline too (uses IAM attached to the job to set permissions).
Hmm. @dci-aloughran I attempted to check the creds in #6427 using `AWS.EC2MetadataCredentials` but to no avail 😖 
Ahah, per https://docs.aws.amazon.com/codebuild/latest/userguide/troubleshooting.html#troubleshooting-versions CodeBuild uses `AWS.RemoteCredentials`, gonna try that.

Resolving patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1dd3a5b51c0..bea7daeeed6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,14 @@
+# 1.48.3 (2019-07-23)
+
+- [Issue 6364 request path](https://github.com/serverless/serverless/pull/6422)
+- [Remove spaces from Cognito Pool Name](https://github.com/serverless/serverless/pull/6419)
+- [Use slss.io for links](https://github.com/serverless/serverless/pull/6428)
+- [Fix regression in EC2 & CodeBuild caused by missing creds check](https://github.com/serverless/serverless/pull/6427<Paste>)
+
+## Meta
+
+- [Comparison since last release](https://github.com/serverless/serverless/compare/v1.48.2...v1.48.3)
+
 # 1.48.2 (2019-07-19)
 
 - [Fix issues in post install and pre uninstall scripts](https://github.com/serverless/serverless/pull/6415)
diff --git a/lib/plugins/aws/lib/validate.js b/lib/plugins/aws/lib/validate.js
index 31ffa85d990..a4be8a5f069 100644
--- a/lib/plugins/aws/lib/validate.js
+++ b/lib/plugins/aws/lib/validate.js
@@ -1,21 +1,52 @@
 'use strict';
 
 const BbPromise = require('bluebird');
+const chalk = require('chalk');
+const userStats = require('../../../utils/userStats');
 
 module.exports = {
   validate() {
-    return new BbPromise((resolve, reject) => {
-      if (!this.serverless.config.servicePath) {
-        const error = new this.serverless.classes.Error(
-          'This command can only be run inside a service directory'
-        );
-        reject(error);
-      }
+    if (!this.serverless.config.servicePath) {
+      const error = new this.serverless.classes.Error(
+        'This command can only be run inside a service directory'
+      );
+      return BbPromise.reject(error);
+    }
 
-      this.options.stage = this.provider.getStage();
-      this.options.region = this.provider.getRegion();
-
-      return resolve();
-    });
+    this.options.stage = this.provider.getStage();
+    this.options.region = this.provider.getRegion();
+    const creds = Object.assign({}, this.provider.getCredentials());
+    delete creds.region;
+    delete creds.signatureVersion;
+    if (
+      Object.keys(creds).length === 0 &&
+      !process.env.ECS_CONTAINER_METADATA_FILE &&
+      !process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI &&
+      !process.env.AWS_CONTAINER_CREDENTIALS_FULL_URI
+    ) {
+      // first check if the EC2 Metadata Service has creds before throwing error
+      const metadataService = new this.provider.sdk.MetadataService({
+        httpOptions: { timeout: 100, connectTimeout: 100 }, // .1 second timeout
+        maxRetries: 0, // retry 0 times
+      });
+      return new BbPromise((resolve, reject) =>
+        metadataService.request('/', (err, data) => {
+          return err ? reject(err) : resolve(data);
+        })
+      )
+        .catch(() => null)
+        .then(identity => {
+          if (!identity) {
+            const message = [
+              'AWS provider credentials not found.',
+              ' Learn how to set up AWS provider credentials',
+              ` in our docs here: <${chalk.green('http://slss.io/aws-creds-setup')}>.`,
+            ].join('');
+            userStats.track('user_awsCredentialsNotFound');
+            throw new this.serverless.classes.Error(message);
+          }
+        });
+    }
+    return BbPromise.resolve();
   },
 };
diff --git a/lib/plugins/aws/provider/awsProvider.js b/lib/plugins/aws/provider/awsProvider.js
index 00e39895d2c..0948e6f56ac 100644
--- a/lib/plugins/aws/provider/awsProvider.js
+++ b/lib/plugins/aws/provider/awsProvider.js
@@ -367,18 +367,6 @@ class AwsProvider {
     if (this.options['aws-profile']) {
       impl.addProfileCredentials(result, this.options['aws-profile']); // CLI option profile
     }
-
-    // Throw an error if credentials are invalid, don't wait for a request to be made to do so
-    if (Object.keys(result).length === 0) {
-      const message = [
-        'AWS provider credentials not found.',
-        ' Learn how to set up AWS provider credentials',
-        ` in our docs here: <${chalk.green('http://slss.io/aws-creds-setup')}>.`,
-      ].join('');
-      userStats.track('user_awsCredentialsNotFound');
-      throw new this.serverless.classes.Error(message);
-    }
-
     result.region = this.getRegion();
 
     const deploymentBucketObject = this.serverless.service.provider.deploymentBucketObject;
diff --git a/package.json b/package.json
index ee20e2c7e7f..e901c6663df 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "serverless",
-  "version": "1.48.2",
+  "version": "1.48.3",
   "engines": {
     "node": ">=6.0"
   },


Test patch:
diff --git a/lib/plugins/aws/invoke/index.test.js b/lib/plugins/aws/invoke/index.test.js
index 08d7febeb41..9ab179a558a 100644
--- a/lib/plugins/aws/invoke/index.test.js
+++ b/lib/plugins/aws/invoke/index.test.js
@@ -86,6 +86,7 @@ describe('AwsInvoke', () => {
       };
       awsInvoke.options.data = null;
       awsInvoke.options.path = false;
+      awsInvoke.provider.cachedCredentials = { accessKeyId: 'foo', secretAccessKey: 'bar' };
 
       // Ensure there's no attempt to read path from stdin
       backupIsTTY = process.stdin.isTTY;
diff --git a/lib/plugins/aws/invokeLocal/index.test.js b/lib/plugins/aws/invokeLocal/index.test.js
index e3e6d05d118..c5f0aff5e07 100644
--- a/lib/plugins/aws/invokeLocal/index.test.js
+++ b/lib/plugins/aws/invokeLocal/index.test.js
@@ -44,6 +44,7 @@ describe('AwsInvokeLocal', () => {
     serverless.config.servicePath = 'servicePath';
     serverless.cli = new CLI(serverless);
     provider = new AwsProvider(serverless, options);
+    provider.cachedCredentials = { accessKeyId: 'foo', secretAccessKey: 'bar' };
     serverless.setProvider('aws', provider);
     awsInvokeLocal = new AwsInvokeLocal(serverless, options);
     awsInvokeLocal.provider = provider;
diff --git a/lib/plugins/aws/lib/validate.test.js b/lib/plugins/aws/lib/validate.test.js
index d21aa79eb83..64dee4c92db 100644
--- a/lib/plugins/aws/lib/validate.test.js
+++ b/lib/plugins/aws/lib/validate.test.js
@@ -9,6 +9,12 @@ chai.use(require('chai-as-promised'));
 
 const expect = chai.expect;
 
+class MetadataService {
+  request(error) {
+    error('error');
+  }
+}
+
 describe('#validate', () => {
   const serverless = new Serverless();
   let provider;
@@ -20,7 +26,9 @@ describe('#validate', () => {
       region: 'us-east-1',
     };
     provider = new AwsProvider(serverless, awsPlugin.options);
+    provider.cachedCredentials = { accessKeyId: 'foo', secretAccessKey: 'bar' };
     awsPlugin.provider = provider;
+    awsPlugin.provider.sdk = { MetadataService };
     awsPlugin.serverless = serverless;
     awsPlugin.serverless.setProvider('aws', provider);
 
@@ -75,5 +83,17 @@ describe('#validate', () => {
         expect(awsPlugin.options.region).to.equal('some-region');
       });
     });
+
+    it('should check the metadata service and throw an error if no creds and no metadata response', () => {
+      awsPlugin.options.region = false;
+      awsPlugin.serverless.service.provider = {
+        region: 'some-region',
+      };
+      provider.cachedCredentials = {};
+
+      return expect(awsPlugin.validate()).to.be.rejected.then(() => {
+        expect(awsPlugin.options.region).to.equal('some-region');
+      });
+    });
   });
 });
diff --git a/lib/plugins/aws/logs/index.test.js b/lib/plugins/aws/logs/index.test.js
index e748a4409c4..957dd7fbf4c 100644
--- a/lib/plugins/aws/logs/index.test.js
+++ b/lib/plugins/aws/logs/index.test.js
@@ -18,7 +18,9 @@ describe('AwsLogs', () => {
       function: 'first',
     };
     serverless = new Serverless();
-    serverless.setProvider('aws', new AwsProvider(serverless, options));
+    const provider = new AwsProvider(serverless, options);
+    provider.cachedCredentials = { accessKeyId: 'foo', secretAccessKey: 'bar' };
+    serverless.setProvider('aws', provider);
     awsLogs = new AwsLogs(serverless, options);
   });
 
diff --git a/lib/plugins/aws/provider/awsProvider.test.js b/lib/plugins/aws/provider/awsProvider.test.js
index 30d1e16c296..593482273cc 100644
--- a/lib/plugins/aws/provider/awsProvider.test.js
+++ b/lib/plugins/aws/provider/awsProvider.test.js
@@ -12,7 +12,6 @@ const os = require('os');
 const path = require('path');
 const overrideEnv = require('process-utils/override-env');
 
-const userStats = require('../../../utils/userStats');
 const AwsProvider = require('./awsProvider');
 const Serverless = require('../../../Serverless');
 const { replaceEnv } = require('../../../../tests/utils/misc');
@@ -241,7 +240,6 @@ describe('AwsProvider', () => {
 
   describe('#request()', () => {
     beforeEach(() => {
-      serverless.service.provider.credentials = { accessKeyId: 'id', secretAccessKey: 'secret' };
       const originalSetTimeout = setTimeout;
       sinon
         .stub(global, 'setTimeout')
@@ -847,7 +845,6 @@ describe('AwsProvider', () => {
     const AwsProviderProxyquired = proxyquire('./awsProvider.js', {
       'aws-sdk': awsStub,
     });
-    let trackStub;
 
     // add environment variables here if you want them cleared prior to your test and restored
     // after it has completed.  Any environment variable that might alter credentials loading
@@ -882,7 +879,6 @@ describe('AwsProvider', () => {
     let originalEnvironmentVariables;
 
     beforeEach(() => {
-      trackStub = sinon.stub(userStats, 'track');
       originalProviderCredentials = serverless.service.provider.credentials;
       originalProviderProfile = serverless.service.provider.profile;
       originalEnvironmentVariables = replaceEnv(relevantEnvironment);
@@ -909,18 +905,17 @@ describe('AwsProvider', () => {
       replaceEnv(originalEnvironmentVariables);
       serverless.service.provider.profile = originalProviderProfile;
       serverless.service.provider.credentials = originalProviderCredentials;
-      trackStub.restore();
     });
 
     it('should set region for credentials', () => {
-      serverless.service.provider.profile = 'notDefault';
       const credentials = newAwsProvider.getCredentials();
       expect(credentials.region).to.equal(newOptions.region);
     });
 
     it('should not set credentials if credentials is an empty object', () => {
       serverless.service.provider.credentials = {};
-      expect(() => newAwsProvider.getCredentials()).to.throw('AWS provider credentials not found.');
+      const credentials = newAwsProvider.getCredentials();
+      expect(credentials).to.eql({ region: newOptions.region });
     });
 
     it('should not set credentials if credentials has undefined values', () => {
@@ -929,7 +924,8 @@ describe('AwsProvider', () => {
         secretAccessKey: undefined,
         sessionToken: undefined,
       };
-      expect(() => newAwsProvider.getCredentials()).to.throw('AWS provider credentials not found.');
+      const credentials = newAwsProvider.getCredentials();
+      expect(credentials).to.eql({ region: newOptions.region });
     });
 
     it('should not set credentials if credentials has empty string values', () => {
@@ -938,7 +934,8 @@ describe('AwsProvider', () => {
         secretAccessKey: '',
         sessionToken: '',
       };
-      expect(() => newAwsProvider.getCredentials()).to.throw('AWS provider credentials not found.');
+      const credentials = newAwsProvider.getCredentials();
+      expect(credentials).to.eql({ region: newOptions.region });
     });
 
     it('should get credentials from provider declared credentials', () => {
@@ -975,17 +972,20 @@ describe('AwsProvider', () => {
 
     it('should not set credentials if empty profile is set', () => {
       serverless.service.provider.profile = '';
-      expect(() => newAwsProvider.getCredentials()).to.throw('AWS provider credentials not found.');
+      const credentials = newAwsProvider.getCredentials();
+      expect(credentials).to.eql({ region: newOptions.region });
     });
 
     it('should not set credentials if profile is not set', () => {
       serverless.service.provider.profile = undefined;
-      expect(() => newAwsProvider.getCredentials()).to.throw('AWS provider credentials not found.');
+      const credentials = newAwsProvider.getCredentials();
+      expect(credentials).to.eql({ region: newOptions.region });
     });
 
     it('should not set credentials if empty profile is set', () => {
       serverless.service.provider.profile = '';
-      expect(() => newAwsProvider.getCredentials()).to.throw('AWS provider credentials not found.');
+      const credentials = newAwsProvider.getCredentials();
+      expect(credentials).to.eql({ region: newOptions.region });
     });
 
     it('should get credentials from provider declared temporary profile', () => {