aws / aws-toolkit-vscode

Amazon Q, CodeCatalyst, Local Lambda debug, SAM/CFN syntax, ECS Terminal, AWS resources
https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.amazon-q-vscode
Apache License 2.0
1.51k stars 436 forks source link

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

Open shawnhind opened 2 years ago

shawnhind commented 2 years ago

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:

{
            "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</xml>

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 '<xml>greeting</xml>'
JadenSimon commented 2 years ago

Thanks for the report! We seem to assume a JSON payload in many different places beyond the launch config, so I'm tracking this issue apart of a larger story.