Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The write operation timed out in lambda update-function-code

I've been trying to deploy a lambda function by using the AWS CLI. The following is the command I'm using and the zip file is ~5MB.

aws lambda update-function-code --function-name <function arn> --zip-file fileb://Lambda-Deployment.zip

I get the following error:

('Connection aborted.', timeout('The write operation timed out',))

Then, I add --cli-connect-timeout 10000 to the above command and try it again, and this time it seems to have worked, I get the output as if it worked. I check on the functions list in the Lambda console and it shows it was last modified recently and the code size to be 5.1MB.

Now, the weird part, when I click on the function in the Lambda console, all the code has disappeared in the Function Code section. There's nothing there. I just get a blank section. I've waited close to an hour after uploading the zip file and nothing shows up.

I've also tried manually uploading the zip file in the Lambda console and I get the same issue. The code disappears.

I have other Lambda functions which have smaller zip files, ~1.5MB, and they all work fine when uploading.

Any help would be greatly appreciated.

like image 333
J.T. Garcia Avatar asked Jan 19 '18 18:01

J.T. Garcia


People also ask

How do I fix the Lambda timeout?

Socket timeout To troubleshoot the retry and timeout issues, first review the logs of the API call to find the problem. Then, change the retry count and timeout settings of the AWS SDK as needed for each use case. To allow enough time for a response to the API call, add time to the Lambda function timeout setting.

What happens when a Lambda function timeout?

When the specified timeout is reached, Amazon Lambda terminates execution of your Lambda function. As a best practice, you should set the timeout value based on your expected execution time to prevent your function from running longer than intended.


2 Answers

For larger packages, you need to first upload to an S3 bucket, and then update Lambda from S3. Sometimes, it can even be due to a poor internet connection while uploading. It will work if you use S3. Here are the commands you need:

Upload to S3:

aws s3 cp Lambda-Deployment.zip s3://your-bucket-name

Create lambda function (when it's the first time):

aws lambda create-function \
  --function-name <function name or arn> \
  --runtime <runtime> \
  --role <role arn> \
  --handler <handle> \
  --code S3Bucket=your-bucket-name,S3Key=Lambda-Deployment.zip

Update function code:

aws lambda update-function-code \
  --function-name <function name or arn> \
  --s3-bucket your-bucket-name \
  --s3-key Lambda-Deployment.zip

You may also read help for all of the above commands

aws s3 help
aws lambda create-function help
aws lambda update-function-code help
like image 91
Renato Byrro Avatar answered Oct 03 '22 10:10

Renato Byrro


You can alternatively use a tool like AWS SAM that automates the process of deploying to S3 and then uploading to Lambda along with managing serverless infrastructure, local debugging and integrations with developer tools. Alternatives include The Serverless Framework and APEX.

like image 27
Taavi Rehemägi Avatar answered Oct 03 '22 12:10

Taavi Rehemägi