aws / aws/aws-toolkit-vscode

SAM debug configurations don't allow non-JSON payloads to send to API

Open
#2,478 1 comment 1 reaction 0 assignees View on GitHub
bug sam service:apigateway
Dominant language
TypeScript
Stars
2k
Forks
807
Avg merge
10h 12m
Merged PRs (30d)
7

Description

**Describe the bug**

When using debug configurations for an AWS SAM application using API invocation you are unable to pass a payload containing anything other than JSON data however this works just fine if you start up the API using SAM CLI and then execute a curl request to the API endpoint. It also works in live environments.

**To Reproduce**
Steps to reproduce the behavior:
1. Create the sample HelloWorld SAM application using the VSCode Toolkit
2. Add an API debug configuration like this one I've included below.
3. Try setting the path to a file that contains XML rather than JSON data.
4. See error saying it's an invalid JSON file.

**Expected behavior**

I should be able to pass a payload containing any type of data I wish, just like you can with a normal API gateway / lambda combination.

Debug configuration showing what I tried:
```json
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "API someapp:SomeApp (java8)",
"invokeTarget": {
"target": "api",
"templatePath": "${workspaceFolder}/someapp/template.yaml",
"logicalId": "SomeApp"
},
"api": {
"path": "/hello",
"httpMethod": "post",
"payload": {
"path": "${workspaceFolder}/someapp/events/test.xml"
},
"headers": {
"accept": "application/json",
"content-type": "application/xml",
}

},
"lambda": {
"runtime": "java8"
}
}
```

Contents of test.xml:
```xml
greeting
```

Here's the steps showing I can accomplish what I"m trying to accomplish outside of the debug configuration but not with it:
1. `sam build --use-container`
2. `sam local start-api`
3. `curl http://localhost:3000/hello -d 'greeting'`

Contributor guide

Open the contributing guide

Research direction

Trace the SAM API debug configuration handling for a payload loaded from the configured path, focusing on where the file is treated as JSON. Compare that behavior with the documented sam local start-api and curl flow. Done means an XML or other non-JSON payload can be sent through the debug configuration while existing JSON payloads continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript, vscode
Domain
api, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.