GCloud Error: Source code size exceeds the limit

Viewed 5654

I'm doing the tutorial of basic fulfillment and conversation setup of api.ai tutorial to make a chat bot, and when I try to deploy the function with the command:

gcloud beta functions deploy --stage-bucket venky-bb7c4.appspot.com --trigger-http

(where 'venky-bb7c4.appspot.com' is the bucket_name) It return the following error message:

ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, message=Source code size exceeds the limit

I've searched but not found any answer, I don't know where is the error. this is the JS file that appear in the tutorial:

    /
 HTTP Cloud Function.

 @param {Object} req Cloud Function request context.
 @param {Object} res Cloud Function response context.
*/
exports.helloHttp = function helloHttp (req, res) {
  response = "This is a sample response from your webhook!" //Default response from the webhook to show it's working


res.setHeader('Content-Type', 'application/json'); //Requires application/json MIME type
  res.send(JSON.stringify({ "speech": response, "displayText": response 
  //"speech" is the spoken version of the response, "displayText" is the visual version
  }));
};
5 Answers

I tried with source option or deploying from the index.js folder and still a different problem exists.

This error usually happens if the code that is being uploaded is large. In my tests I found more than 100MB lead to the mentioned error.

However, To resolve this there are two solutions.

  1. Update .gcloudignore to ignore the folders which aren't required for your function
  2. Still if option 1 doesn't resolve, you need to create a bucket in storage and mention it with --stage-bucket option.

Create a new bucket for deployment (one time)

gsutil mb my-cloud-functions-deployment-bucket

The bucket you created needs to be unique else it throws already created

Deploy

gcloud functions deploy subscribers-firestoreDatabaseChange
--trigger-topic firestore-database-change
--region us-central1
--runtime nodejs10
--update-env-vars "REDIS_HOST=10.128.0.2"
--stage-bucket my-cloud-functions-deployment-bucket

I had similar problems while deploying cloud functions. What is working for me was specifying the js files source folder.

gcloud functions deploy functionName --trigger-http **--source path_to_project_root_folder**

Also be sure to include all unnecessary folders in .gcloudignore.

Ensure the package folder has a .gitignore file (excluding node_modules).

The most recent version of gcloud requires it in order to not load node_modules. My code size went from 119MB to 17Kb.

Once I've added the .gitignore file, the log printed as well

created .gcloudignore file. See `gcloud topic gcloudignore` for details.
Related