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.46k stars 403 forks source link

SAM run/debug: eliminate temporary directory #2050

Open justinmk3 opened 2 years ago

justinmk3 commented 2 years ago

Problem

Toolkit currently always builds and runs from a temporary /tmp/vstck-xx directory. This confuses tooling and may defeat SAM CLI "cache" functionality.

Reason for the temporary directory:

Related notes:

Proposal

  1. what does aws-toolkit-jetbrains do?
  2. Switch to building in the user's workspace.
    • auto-add to .git/info/excludes ?
  3. in .aws-sam/ directory?
    • Bonus: works better with sam invocations outside of the Toolkit
  4. Strategy: instead of "temp dir per execution", change the model to "temp dir per template"?

Alternative:

  1. Mostly keep the same logic, but always re-use the same /tmp/vstck-xx directory for the same template.yaml
    • risk: does this complicate the logic that maps the temporary template.yaml from the actual template.yaml ? #1159

Alternative:

  1. are we passing the temporary as --build-dir correctly? Maybe this will avoid needing to remap the paths in the temporary template.yaml #1159 #990 ?
danw-mpl commented 2 years ago

This would be amazing. We wait over two minutes every time we invoke a function because the cache is wiped out. Super frustrating when trying to develop.

@justinmk3 Regarding JetBrains, we experience the same problem.

JadenSimon commented 2 years ago

The next release (1.30.0) will include a way to set a directory via a buildDir field in the launch config (under "sam") Example config:

"type": "aws-sam",
"request": "direct-invoke",
"name": "lambda-go1.x:HelloWorldFunction (go1.x)",
"invokeTarget": {
    "target": "template",
    "templatePath": "${workspaceFolder}/lambda-go1.x/template.yaml",
    "logicalId": "HelloWorldFunction"
},
"lambda": {
    "payload": {},
    "environmentVariables": {},
    "runtime": "go1.x"
},
"sam": {
    "buildDir": "${workspaceFolder}/buildDir"
}
justinmk3 commented 2 years ago

https://github.com/aws/aws-toolkit-vscode/pull/2755 mitigates some issues with the temporary directory by setting the process working directory.