How to use the @serverless/core.utils.hashFile function in @serverless/core

To help you get started, we’ve selected a few @serverless/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github serverless-components / aws-lambda / serverless.js View on Github external
this.context.status('Deploying Dependencies')
      this.context.debug(`Packaging lambda code from ${config.code}.`)
      this.context.debug(`Uploading dependencies as a layer for lambda ${config.name}.`)

      const promises = [pack(config.code, config.shims, false), layer(layerInputs)]
      const res = await Promise.all(promises)
      config.zipPath = res[0]
      config.layer = res[1]
    } else {
      this.context.status('Packaging')
      this.context.debug(`Packaging lambda code from ${config.code}.`)
      config.zipPath = await pack(config.code, config.shims)
    }

    config.hash = await utils.hashFile(config.zipPath)

    let deploymentBucket
    if (config.bucket) {
      deploymentBucket = await this.load('@serverless/aws-s3')
    }

    const prevLambda = await getLambda({ lambda, ...config })

    if (!prevLambda) {
      if (config.bucket) {
        this.context.debug(`Uploading ${config.name} lambda package to bucket ${config.bucket}.`)
        this.context.status(`Uploading`)

        await deploymentBucket.upload({ name: config.bucket, file: config.zipPath })
      }