lib/plugins/aws/configCredentials/awsConfigCredentials.js/AwsConfigCredentials/configureCredentials
class AwsConfigCredentials:  configureCredentials() {
    // sanitize
    this.options.provider = this.options.provider.toLowerCase();
    this.options.profile = this.options.profile ? this.options.profile : 'default';

    // resolve if provider option is not 'aws'
    if (this.options.provider !== 'aws') {
      return BbPromise.resolve();
    }

    // validate
    if (!this.options.key || !this.options.secret) {
      throw new this.serverless.classes.Error('Please include --key and --secret options for AWS.');
    }

    this.serverless.cli.log('Setting up AWS...');
    this.serverless.cli.log('Saving your AWS profile in "~/.aws/credentials"...');

    if (!os.homedir()) {
      throw new this.serverless.classes
        .Error('Can\'t find home directory on your local file system.');
    }

    // check if ~/.aws/credentials exists
    const configDir = path.join(os.homedir(), '.aws');
    const credsPath = path.join(configDir, 'credentials');

    if (this.serverless.utils.fileExistsSync(credsPath)) {
      // check if credentials files contains anything
      const credsFile = this.serverless.utils.readFileSync(credsPath);

      // if credentials file exists w/ profile, exit
      if (credsFile.length && credsFile.indexOf(`[${this.options.profile}]`) > -1) {
        this.serverless.cli.log(
          `Failed! ~/.aws/credentials exists and already has a "${this.options.profile}" profile.`);
        return BbPromise.resolve();
      }
    } else {
      // create the credentials file alongside the .aws directory if it's not yet present
      fse.ensureFileSync(credsPath);
    }

    // write credentials file with 'default' profile
    this.serverless.utils.appendFileSync(
      credsPath,
      `[${this.options.profile}]
aws_access_key_id=${this.options.key}
aws_secret_access_key=${this.options.secret}
`); // Keep line break at the end. Otherwise will break AWS CLI.

    this.serverless.cli.log(
      `Success! Your AWS access keys were stored under the "${this.options.profile}" profile.`);

    return BbPromise.resolve();
  }