aws / aws-toolkit-jetbrains

AWS Toolkit for JetBrains - a plugin for interacting with AWS from JetBrains IDEs
https://plugins.jetbrains.com/plugin/11349-aws-toolkit
Apache License 2.0
753 stars 219 forks source link

Update Function Code with TypeScript #2817

Open iheffernan opened 3 years ago

iheffernan commented 3 years ago

Describe the bug I have a Lambda function written in TypeScript that I can run and debug locally. However, if I try to use AWS Explorer to Update Function Code of a deployed Lambda and then test that deployed Lambda in the AWS Console I always get the following error (my lambda function file is app.ts...

{ "errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'app'\nRequire stack:\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js", "trace": [ "Runtime.ImportModuleError: Error: Cannot find module 'app'", "Require stack:", "- /var/runtime/UserFunction.js", "- /var/runtime/index.js", " at _loadUserApp (/var/runtime/UserFunction.js:100:13)", " at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)", " at Object.<anonymous> (/var/runtime/index.js:43:30)", " at Module._compile (internal/modules/cjs/loader.js:1072:14)", " at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)", " at Module.load (internal/modules/cjs/loader.js:937:32)", " at Function.Module._load (internal/modules/cjs/loader.js:778:12)", " at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)", " at internal/main/run_main_module.js:17:47" ] }

To reproduce

  1. Create a SAM project in WebStorm
  2. Create and test a Local configuration pointing to src/app.lambdaHandler
  3. Use AWS Explorer to Update Function Code (or create New Lambda) referencing the same handler path of src/app.lambdaHandler

Expected behavior I would expect the deployed Lambda to behave identically to when I run it locally.

Screenshots Screenshots of my local project layout, including the main handler and my local Lambda config are below...

Screen Shot 2021-09-24 at 10 18 27 Screen Shot 2021-09-24 at 10 18 46

Your Environment

Additional context

iheffernan commented 3 years ago

So an update here. I can workaround this by Updating the function code with AWS Toolkit, then going into the AWS Console and manually changing the Handler to point to dist/src/app.lambdaHandler. Would be nice, though, if we could cut out that additional step.

abrooksv commented 3 years ago

I am not sure our custom TS step gets executed in that flow.

We will have to take a look.

FYI, you can update the handler in the Update Function Configuration dialog if you wish to avoid going to the console.

iheffernan commented 3 years ago

That's the problem - the console allows me to set the handler to dist/src/app.lambdaHandler, but if I try to use that path in the Update Function dialogs it gives me an error that says Must be able to locate the handler in the project in order to deploy to Lambda. Almost like there's some overzealous validation of the Handler path in the Toolkit dialog.

iheffernan commented 3 years ago

FWIW - once I do set the Handler path in the AWS Console it is retained, regardless of what I put in the AWS Explorer dialog when I do Update Function.

abrooksv commented 3 years ago

It is over zealous because we currently backtrack from the handler to find where to build the function from.

The fact that the handler doesn't update is probably actually a bug 😄

I was referring to the Update Function Configuration dialog, which does NOT update any code Screen Shot 2021-09-28 at 11 36 28 AM :

iheffernan commented 3 years ago

I take that last comment back - it does get overwritten on each deployment from AWS Explorer

iheffernan commented 3 years ago

Ok, that makes sense. Yes, I can update the configuration, but then when I try to actually update the function I get the Must be able to locate... error.

Like I said, I have a workaround for now, but it would be nice because I'll eventually forget to make the update in the console!

iheffernan commented 2 years ago

I wanted to circle back on this to see if this was something that you would be able to allow in future versions, e.g. specifying the path to the transpiled code as the Handler in the the Update Function Code dialog.

It is still possible to do this in 2 steps by first updating the code and pointing to the source directory that contains the TypeScript handler and then using the Update Function Configuration dialog to change the Handler to the transpiled code. It would just be nice if you could specify the transpiled Handler when updating the code.

Thanks again...

Dec- commented 2 years ago

Still the same issue, any progress?

abhishek-parative commented 9 months ago

Still seeing this error when using the AWS Tookit, but no error when running SAM CLI in Terminal