Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAM run/debug: eliminate temporary directory #2050

Open
justinmk3 opened this issue Sep 20, 2021 · 3 comments
Open

SAM run/debug: eliminate temporary directory #2050

justinmk3 opened this issue Sep 20, 2021 · 3 comments
Labels
feature-request New feature or enhancement. May require GitHub community feedback. performance sam

Comments

@justinmk3
Copy link
Contributor

justinmk3 commented Sep 20, 2021

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:

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

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

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 YAML Handling Improvements #1159 Use existing template for template invoke-targets #990 ?
@justinmk3 justinmk3 added performance sam feature-request New feature or enhancement. May require GitHub community feedback. labels Sep 20, 2021
@danw-mpl
Copy link

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
Copy link
Contributor

JadenSimon commented Sep 30, 2021

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
Copy link
Contributor Author

#2755 mitigates some issues with the temporary directory by setting the process working directory.

justinmk3 pushed a commit that referenced this issue Jul 11, 2022
Problem:
All of our SAM CLI invocations are ran without an explicit working directory.
This creates tons of hard-to-diagnose problems.

Solution:
* Explicitly set a working directory for `sam build` to the template's
  directory. This mimics the typical situation when running `sam build` in
  a terminal.
    * This correctly creates a `.aws-sam` directory adjacent to the target
      template.
* Other `sam` commands are still affected although they are harder to change
  without breaking things due to the temporary directory :/ 
* The way the Toolkit + SAM CLI interact is incredibly brittle and this
  solution is just a mitigation.

ref #2050
ref #2395
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or enhancement. May require GitHub community feedback. performance sam
Projects
None yet
Development

No branches or pull requests

3 participants