AWS SAM Direct Invoke - Invalid JSON in payload file
See original GitHub issueI am trying to invoke a Lambda function locally using the AWS SAM tools in VS Code.
I have this debug configuration in my launch.json file:
{
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "SendEmail",
"invokeTarget": {
"target": "template",
"templatePath": "${workspaceFolder}/LambdaExampleProject/sam-template.yml",
"logicalId": "SendEmail"
},
"lambda": {
"runtime": "dotnet5.0",
"environmentVariables": {},
"payload": {
"path": "${workspaceFolder}/LambdaExampleProject/sample-payloads/SendEmailSQSPayload.json"
}
}
}
]
}
And this is the contents of the payload file SendEmailSQSPayload.json:
{
"Records": [
{
"messageId": "059f36b4-87a3-44ab-83d2-661975830a7d",
"receiptHandle": "AQEBwJnKyrHigUMZj6rYigCgxlaS3SLy0a...",
"body": "Test message.",
"attributes": {
"ApproximateReceiveCount": "1",
"SentTimestamp": "1545082649183",
"SenderId": "AIDAIENQZJOLO23YVJ4VO",
"ApproximateFirstReceiveTimestamp": "1545082649185"
},
"messageAttributes": {},
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3",
"eventSource": "aws:sqs",
"eventSourceARN": "arn:aws:sqs:us-east-2:123456789012:my-queue",
"awsRegion": "ap-southeast-2"
}
]
}
It is indeed valid JSON in the payload file but VS Code still throws this error:
Invalid JSON in payload file
Am I doing something wrong here? It seems like something that should be super simple according to the documentation.
Thanks in advance for any advice
- OS: Windows 10 x64
- VS Code version: 1.66.2
- AWS Toolkit extension version: 1.37.0
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Configuration options for debugging serverless applications
When you open the launch.json file to edit debug configurations, you can use the VS ... AWS SAM: Direct Lambda handler invoke /...
Read more >sam local invoke - AWS Serverless Application Model
Invoke a local Lambda function using the sam local invoke command from the AWS ... -n , --env-vars PATH, The JSON file that...
Read more >Invoke - AWS Lambda - AWS Documentation
The request accepts the following binary data. Payload. The JSON that you want to provide to your Lambda function as input. You can...
Read more >Troubleshoot invocation issues in Lambda
If you invoke your function directly, you see any invocation errors in the response from Lambda. If you invoke your function asynchronously with...
Read more >Troubleshooting payloads - AWS Lambda
The event payload is a JSON structure that may contain arrays and nested ... However, when a larger JPG file is provided as...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks so much @JadenSimon . That was exactly the problem. The JSON file had UTF-8 with BOM encoding!
After saving the file as plain UTF-8, it now reads the file in fine and all works great. Both absolute files path and relative file paths work including the reference of
${workspaceFolder}(as in my original post).Thanks again.
Glad to hear! We’re looking into adding better detection for this as BOM problems are not too uncommon. And they’re very frustrating to debug.