Lambda timeout after 1 second - amazon-web-services

According to https://docs.aws.amazon.com/lambda/latest/dg/limits.html Lambda functions are supposed to timeout after 5 minutes but mine is getting a task timed out after 1 second. It reads a small text file from an S3 bucket, parses it and performs an action.
How can I increase the timeout?
Edit: after moving it to a different region I now get the same problem after a much more generous 3 seconds. I now have another problem which is there's no CloudFront trigger options in the eu-west-1 and eu-west-2 regions which I need to run it.

You can increase the lambda function timeout by 2 ways
Use the aws console
Use the CLI
Using AWS Console open the lambda function and modify the timeout setting over there
Using CLI use the --timeout flag to increase the timeout
https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-configuration.html

Related

SQS invoke multiple lambda at same time

I am new in aws sqs as of now I understand sqs have a queue which is storing request messages (parameter) then our attached lambda will fetch numbers of messages based on the batch file which we set on lambda.
so if the sqs queue has 10000 messages and the lambda batch is set to 100 then in each pulling lambda which fetches 100 messages from the queue and executes all until all request are processed then again it will pull 100 messages and so on?
so as of now, I understand lambda will wait for the next pulling until the previous pulling process is finished.
hope I am correct if not please correct me.
now my requirement is lambda should not wait to finish the previous pulling instead it should pull the next 100 messages and execute parallelly for eg lambda should create a different instance(something like this) and each instance pulls 100 100 messages and execute parallelly.
In the situation you describe, the AWS Lambda service will automatically run multiple AWS Lambda functions based upon the concurrency settings of your function.
See: Lambda function scaling - AWS Lambda
The default is to permit up to 1000 concurrent executions of an AWS Lambda function.
Therefore, you do not need to change anything. It will automatically create multiple instances of the Lambda function in parallel and pass (up to) 100 messages to each execution.
For a really good series of articles to understand how AWS Lambda operates, see: Operating Lambda: Performance optimization – Part 1 | AWS Compute Blog

AWS Lambda function: Timeout after 900 secs

I am invoking an AWS Lambda function locally using aws-sam cli command and I have set the Timeout property to 900 seconds but still it shows function timeout error. However, when I was invoking this function in lambda handler in AWS Console these 900 seconds were enough for the inferencing.
Please help me figure out a solution for this issue and what is the maximum limit I can go for Timeout?
AWS Lambda functions (as at July 2021) can only run for a maximum of 15 minutes (which is 900 seconds).
Some people do 'interesting' things like:
Call another Lambda function to continue the work, or
Use AWS Step Functions to orchestrate multiple AWS Lambda functions
However, it would appear that your use-case is Machine Learning, which does not like to have operations stopped in the middle of processing. Therefore, AWS Lambda is not suitable for your use-case.
Instead, I would recommend using Amazon EC2 spot instances, which will likely be lower-cost for your use-case. While spot instances might occasionally be terminated, your use-case can probably handle the need to re-run some processing if this happens.

AWS Lambda with Provisioned Concurrency still experiencing long startup times

Using a SAM template to deploy an apigateway that calls a couple of lambdas.
All lambdas are written in java11 and are connected to a VPC. This adds a lot of delay between calling the function and the code actually starting up (about 30 seconds).
Used
AutoPublishAlias: "latestAlias"
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions:
1
to enable Provisioned Concurrency but i still get long starts of 30 seconds from time to time.
Also tried using ping events via AWS::Events::Rule to call the lambdas every 9 minutes to keep them warn (i recall reading that 15 minutes of inactivity leads to lambda containers being destroyed). Also left Provisioned Concurrency enabled while doing this, and I still see cold starts. I also see new files being created in CloudWatch logs, indicating that a new container has been spun up.
Using xray to validate that i don't have multiple requests at the same time that might trigger the creating of a new container.
Am I missing something in enabling this? From the documentation i understand that "initialization" should not appear in xray once the lambda has been started. Also, AWS Hyperplane was supposed to reduce lambda-VPC integration times to around 1 second (deploying on eu-central-1 which should have Hyperplane for a while now).

How to receive an endless WebSocket data source using AWS Lambda?

I want to crawl data from a WebSocket data source, usually WebSocket data is an endless stream, while an AWS Lambda function has a Timout limit, the maximum allowed value is 900 seconds.
If my Lambda function acts as a WebSocket client and connects to a WebSocket url, e.g., wss://ws-feed-public.sandbox.pro.coinbase.com, it starts to receive data for 900 seconds and get terminated by then.
How to keep my Lamda function running forever? Thanks!
Right now I'm running my crawler inside a Linux VM, is it possible to migrate it to AWS Lambda?
AWS Lambda functions run for a maximum of 900 seconds (15 minutes).
There is no way to extend this.
You should continue using an Amazon EC2 instance or a container (ECS, Fargate).
Fun fact: When initially released, the limit was 3 minutes. It was later extended to 5 minutes, then to 15 minutes.

Timeout problems with bulk processing of files using AWS Lambda

I have a lambda function which I'm expecting to exceed 15 minutes of execution time. What should I do so it will continuously run until I processed all of my files?
If you can, figure out how to scale your workload horizontally. This means splitting your workload so it runs on many lambdas instead of one "super" lambda. You don't provide a lot of details so I'll list a couple common ways of doing this:
Create an SQS queue and each lambda takes one item off of the queue and processes it.
Use an S3 trigger so that when a new file is added to a bucket a lambda processes that file.
If you absolutely need to process for longer than 15 minutes you can look into other serverless technologies like AWS Fargate. Non-serverless options might include AWS Batch or running EC2.
15 minutes is the maximum execution time available for AWS Lambda functions.
If your processing is taking more than that, then you should break it into more than one lambda. You can trigger them in sequence or in parallel depending on your execution logic.