lib/plugins/aws/package/compile/layers/index.js/AwsCompileLayers/compileLayer
class AwsCompileLayers:  compileLayer(layerName) {
    const newLayer = this.cfLambdaLayerTemplate();
    const layerObject = this.serverless.service.getLayer(layerName);
    layerObject.package = layerObject.package || {};

    const artifactFileName = this.provider.naming.getLayerArtifactName(layerName);
    const artifactFilePath = layerObject.package && layerObject.package.artifact
      ? layerObject.package.artifact
      : path.join(this.serverless.config.servicePath, '.serverless', artifactFileName);

    if (this.serverless.service.package.deploymentBucket) {
      newLayer.Properties.Content.S3Bucket = this.serverless.service.package.deploymentBucket;
    }

    const s3Folder = this.serverless.service.package.artifactDirectoryName;
    const s3FileName = artifactFilePath.split(path.sep).pop();
    newLayer.Properties.Content.S3Key = `${s3Folder}/${s3FileName}`;

    newLayer.Properties.LayerName = layerObject.name || layerName;
    if (layerObject.description) {
      newLayer.Properties.Description = layerObject.description;
    }
    if (layerObject.licenseInfo) {
      newLayer.Properties.LicenseInfo = layerObject.licenseInfo;
    }
    if (layerObject.compatibleRuntimes) {
      newLayer.Properties.CompatibleRuntimes = layerObject.compatibleRuntimes;
    }

    const layerLogicalId = this.provider.naming.getLambdaLayerLogicalId(layerName);
    const newLayerObject = {
      [layerLogicalId]: newLayer,
    };

    if (layerObject.allowedAccounts) {
      layerObject.allowedAccounts.map(account => {
        let parsedAccount = account;
        // cast to string if account is number
        if (typeof account === 'number' && !isNaN(account)) {
          parsedAccount = `${account}`;
        }
        const newPermission = this.cfLambdaLayerPermissionTemplate();
        newPermission.Properties.LayerVersionArn = { Ref: layerLogicalId };
        newPermission.Properties.Principal = parsedAccount;
        const layerPermLogicalId = this.provider.naming.getLambdaLayerPermissionLogicalId(
          layerName, parsedAccount);
        newLayerObject[layerPermLogicalId] = newPermission;
        return newPermission;
      });
    }

    _.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources,
      newLayerObject);

    // Add layer to Outputs section
    const layerOutputLogicalId = this.provider.naming
      .getLambdaLayerOutputLogicalId(layerName);
    const newLayerOutput = this.cfOutputLayerTemplate();

    newLayerOutput.Value = { Ref: layerLogicalId };

    _.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Outputs, {
      [layerOutputLogicalId]: newLayerOutput,
    });
  }