Skip to content

Add Lambda dependencies layer (PyGithub, requests) #34

Description

@ibrahimcesar

Description

The contribute Lambda function requires external Python dependencies (PyGithub, requests) that need to be packaged as a Lambda layer.

Tasks

Create Lambda Layer

  • Create requirements.txt for Lambda
    PyGithub>=2.0.0
    requests>=2.28.0
    
  • Build layer for Lambda runtime
    mkdir -p python
    pip install -r requirements.txt -t python/
    zip -r layer.zip python/
  • Or use Docker for correct architecture:
    docker run --rm -v $(pwd):/var/task \
      public.ecr.aws/sam/build-python3.11 \
      pip install -r requirements.txt -t python/

Update CDK Stack

  • Add Lambda layer definition
    const dependenciesLayer = new lambda.LayerVersion(this, 'DependenciesLayer', {
      code: lambda.Code.fromAsset('lambda/layer.zip'),
      compatibleRuntimes: [lambda.Runtime.PYTHON_3_11],
      description: 'PyGithub and requests dependencies',
    });
  • Attach layer to contribute function
    const contributeFunction = new lambda.Function(this, 'ContributeFunction', {
      // ...
      layers: [dependenciesLayer],
    });

Alternative: Bundle Dependencies

  • Or use inline dependencies with pip install -t

Acceptance Criteria

  • Lambda function can import PyGithub and requests
  • No import errors at runtime
  • Layer version tracked in CDK

Related Files

  • interactive/lambda/contribute.py
  • interactive/infra/lib/interactive-stack.ts

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    infrastructureInfrastructure and toolinginteractiveInteractive platform features

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions