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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With