AWS Lambda VScode launch.json

Viewed 956

Recently AWS introduced launch configurations support for SAM debugging in the AWS Toolkit for VS Code Ref : https://aws.amazon.com/blogs/developer/introducing-launch-configurations-support-for-sam-debugging-in-the-aws-toolkit-for-vs-code/

It means we cant use templates.json file, instead need to use launch.json to send in your event to lambda.

I want to send a test event to lambda function (a SQS message). Before introducing launch configuration templates.json had it like this (and it worked fine):

    "templates": {
 "xxxxxxxx/template.yaml": {
      "handlers": {
        "xxxxxxxxx.lambdaHandler": {
          "event": {
            "Records": [
                {
                    "messageId": "xxxxxxxxxxxxxxxx",
                    "receiptHandle": "xxxxxxxxxxxxxxxx",
                    "body": "{\"operation\": \"publish\", \"data\": { \"__typename\": \"xxxxxxxxxxxxxxxx\", \"id\": \"xxxxxxxxxxxxxxxx\" }}",                            
                    "attributes": {
                        "ApproximateReceiveCount": "1",
                        "SentTimestamp": "xxxxxxxxxxxxxxxx",
                        "SequenceNumber": "xxxxxxxxxxxxxxxx",
                        "MessageGroupId": "xxxxxxxxxxxxxxxx",
                        "SenderId": "xxxxxxxxxxxxxxxx:LambdaFunctionTest",
                        "MessageDeduplicationId": "xxxxxxxxxxxxxxxx",
                        "ApproximateFirstReceiveTimestamp": "xxxxxxxxxxxxxxxx"
                    },
                    "messageAttributes": {            
                      "environment": {
                      "DataType": "String",
                      "stringValue": "Dev"
                    }},
                    "md5OfBody": "xxxxxxxxxxxxxxxx",
                    "eventSource": "aws:sqs",
                    "eventSourceARN": "arn:aws:sqs:us-east-1:xxxxxxxxxxxxxxxx:xxx.fifo",
                    "awsRegion": "us-east-1"
                }
            ]
        },
          "environmentVariables": {}
        }

............

But in launch.json , i pasted the Records in the following way and it is not excepting, see also attached jpg screenshot.

{
"configurations": [
    {
        "type": "aws-sam",
        "request": "direct-invoke",
        "name": "xxxxxxxx)",
        "invokeTarget": {
            "target": "code",
            "projectRoot": "xxxxxxxx",
            "lambdaHandler": "xxxxxxxx.lambdaHandler"
        },
        "lambda": {
            "runtime": "nodejs12.x",
            "payload": {
                "json": {
                    "Records": [
                    {
                        "messageId": "xxxxxxxxxxxxxxxx",
                        "receiptHandle": "xxxxxxxxxxxxxxxx",
                        "body": "{\"operation\": \"publish\", \"data\": { \"__typename\": \"xxxxxxxxxxxxxxxx\", \"id\": \"xxxxxxxxxxxxxxxx\" }}",                            
                        "attributes": {
                            "ApproximateReceiveCount": "1",
                            "SentTimestamp": "xxxxxxxxxxxxxxxx",
                            "SequenceNumber": "xxxxxxxxxxxxxxxx",
                            "MessageGroupId": "xxxxxxxxxxxxxxxx",
                            "SenderId": "xxxxxxxxxxxxxxxx:LambdaFunctionTest",
                            "MessageDeduplicationId": "xxxxxxxxxxxxxxxx",
                            "ApproximateFirstReceiveTimestamp": "xxxxxxxxxxxxxxxx"
                        },
                        "messageAttributes": {            
                          "environment": {
                          "DataType": "String",
                          "stringValue": "Dev"
                        }},
                        "md5OfBody": "xxxxxxxxxxxxxxxx",
                        "eventSource": "aws:sqs",
                        "eventSourceARN": "arn:aws:sqs:us-east-1:xxxxxxxxxxxxxxxx:xxx.fifo",
                        "awsRegion": "us-east-1"
                    }
                ]
               },                    
            },
        }
    },

enter image description here

Blockquote

0 Answers
Related