afx
afx

Reputation: 13

Debugging AWS CDK Python Lambda in IntelliJ IDEA

I have created a simple AWS Lambda in Python that returns "hello, World!" using AWS CDK.

I'm able to synthesize & deploy the stack using CDK. I'm able to locally invoke the lambda using SAM. But, I'm not able to debug the lambda locally from IntelliJ IDEA.

My main project directory is called greeting-service and the directory structure looks like this - Directory structure

greeting-service/lib/greeting-service-stack.ts

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as greeting_service from '../lib/greeting-service'

export class GreetingServiceStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new greeting_service.GreetingService(this, 'GreetingService');
  }
}

greeting-service/lib/greeting-service.ts

import * as cdk from "aws-cdk-lib";
import {Construct} from "constructs";
import * as apigateway from "aws-cdk-lib/aws-apigateway";
import * as lambda from "aws-cdk-lib/aws-lambda";

export class GreetingService extends Construct {
    constructor(scope: Construct, id: string) {
        super(scope, id);

        const greetingApiGateway = new apigateway.RestApi(this, "Greeting API", {
            restApiName: "Greeting API",
            description: "This API says Hello"
        });

        const greetingLambdaFunction = new lambda.Function(this, 'GreetingFunction', {
            runtime: lambda.Runtime.PYTHON_3_8,
            handler: 'greeting.handler',
            code: lambda.Code.fromAsset("resources")
        });

        const greetingIntegration = new apigateway.LambdaIntegration(greetingLambdaFunction, {
            requestTemplates: {
                "application/json": '{ "statusCode": "200" }'
            }
        });

        greetingApiGateway.root.addMethod("GET", greetingIntegration);
    }
}

greeting-service/resources/greeting.py

import json


def handler(event, context):
    print('Request: {}', json.dumps(event))
    print('Context {}', context)
    return {
        "statusCode": 200,
        "headers": {
            "Content-Type": "application/json"
        },
        "body": json.dumps({
            "greeting ": "hello, World!"
        })
    }

I have installed the AWS Toolkit for JetBrains. I have connected it to my AWS account. I have selected 'show gutter icons for all potential AWS Lambda handlers' under IntelliJ IDEA > Settings > Tools > AWS > Lambda

I still don't see the gutter icon and hence cannot debug - No gutter icon for Lambda handler

Upvotes: 0

Views: 480

Answers (0)

Related Questions