aws-toolkit-vscode icon indicating copy to clipboard operation
aws-toolkit-vscode copied to clipboard

SAM run/debug: eliminate temporary directory

Open justinmk3 opened this issue 4 years ago • 3 comments

Problem

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

  • #1988
  • #2024

Reason for the temporary directory:

  • we wanted to avoid building artifacts into the user's workspace (which then might be accidentally committed)

Related notes:

  • A similar but not identical concept is that Toolkit copies the actual template.yaml to a temporary counterpart.
    • #1159
    • #990

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 ?

justinmk3 avatar Sep 20 '21 17:09 justinmk3

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.

danw-mpl avatar Sep 21 '21 16:09 danw-mpl

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"
}

JadenSimon avatar Sep 30 '21 18:09 JadenSimon

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

justinmk3 avatar Jul 11 '22 21:07 justinmk3