Search code examples
amazon-web-servicesaws-lambdabilling

AWS Lambda function Billed duration includes Init Duration as well when using Lambda container?


This is what I see in my AWS Cloudwatch logs:

REPORT RequestId: aaaaaa-bbbb-cccc-yyyy-xxxxxxxx    Duration: 3322.91 ms    
Billed Duration: 9995 ms    Memory Size: 256 MB Max Memory Used: 137 MB 
Init Duration: 6671.44 ms   

My question is, why does Billed Duration include Init duration as well ?

Billed Duration (9995 ms) = Init Duration(6671.44ms) + Duration(3322.91ms)

I'm using a Lambda container which is based on the aws provided lambda python:3.8 lambda container. Is the Init Duration being included in Billed Duration because I'm using my own container ?

Below is the Dockerfile on which the container is based on:

FROM public.ecr.aws/lambda/python:3.8

COPY requirements.txt /var/task
RUN pip3 install -r /var/task/requirements.txt

COPY . .

CMD ["handler/run"]

Less relevant info:

In the container, I'm hitting an api, parsing the results and uploading to dynamodb.


Solution

  • If you take a look at Lambda pricing details documentation here - you will see a small asterick (*) :-) mentioning below

    Duration charges apply to code that runs in the handler of a function as well as initialization code that is declared outside of the handler.

    So yes the initialization code (init) is also considered in billing as well. As you can see from the Lambda execution model here , everything before handler invoke is considered to be part of init phase.