Skip to content

Bug: High import time when importing ApiGatewayResolver because of CodePipelineJobEvent #2352

Closed
@darnley

Description

@darnley

Expected Behaviour

Do not import CodePipelineJobEvent when using ApiGatewayResolver, because the CodePipelineJobEvent will import boto3 and huge increase the AWS Lambda Cold Start or prevent boto3 from being called unexpectedly.

Current Behaviour

When importing ApiGatewayResolver, it is importing CodePipelineJobEvent and boto3. However, ApiGatewayResolver does not need boto3.

This behaviour is increasing the AWS Lambda cold start. When I use a profiling tool in my machine, it seems that just to import it is costing ~200ms. When running on AWS with a 800MB runtime, it is costing ~400ms.

According to the profiling in this use case, importing CodePipelineJobEvent costed 61.9% of time, but it will not be used. That is weird.

image
profile.log

Code snippet

from aws_lambda_powertools.logging import Logger
from aws_lambda_powertools.metrics import Metrics
from aws_lambda_powertools.tracing import Tracer
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver

Possible Solution

No response

Steps to Reproduce

  1. Put this code on a Python file;
  2. Install tuna package using pip install tuna;
  3. Run command
python -X importtime MY_SCRIPT.py 2> profile.log && tuna profile.log

Browser will appear with the profiling graph.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.9

Packaging format used

PyPi

Debugging logs

No response

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions