I can’t for the life of me understand how I would set up SAM to run my Typescript/nodejs api locally.
I run sam local start-api
and everything kind of starts up. Lots and lots of debug logging that doesn’t tell me anything. Once I try to invoke the API endpoint with CURL I get the following error message:
26 Apr 2024 00:43:22,108 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 129 InvokeID=
26 Apr 2024 00:43:22,109 [ERROR] (rapid) Invoke failed error=Runtime exited with error: exit status 129 InvokeID=3506a416-5cd1-42a3-ba56-45ffa76d2369
26 Apr 2024 00:43:22,110 [ERROR] (rapid) Invoke DONE failed: Sandbox.Failure
Here’s an example of how I set up a lambda function in the SAM template yaml:
GetAuthenticatedUserDetailsFunction:
CodeUri: ../
Handler: GetAuthenticatedUserDetails.lambdaHandler
Events:
GetAuthenticatedUserDetails:
Type: Api
Properties:
RestApiId: !Ref api
Path: /gaud
Method: get
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action: "rds-db:connect"
Resource: !Sub 'arn:aws:rds-db:${AWS::Region}:${AWS::AccountId}:dbuser:${DBProxyPRXID}/*'
Metadata:
BuildMethod: esbuild
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
EntryPoints:
- src/GetAuthenticatedUserDetails.ts
What am I doing wrong? I thought the sam cli would be smart enough to figure all this out by itself?
Here are some things that I already know
- Entrypoints attribute contains the “src” directory. If I move that dir to the CodeUri attribute then sam build fails by saying that esbuild doesn’t exist on my machine (but magically does exist with this config)
- The sam build command transpiles all the .ts code to .js dirs in the ./aws-sam directory. But! It has a different structure where the code is compiled per function.
I understand that the error points to the fact that sam local can’t find the function in whatever directory it is looking in. The Typescript code is transpiled into a .aws-sam/ directory that has a completely different structure (I assume it’s self contained and will be zipped up for deployment).
I did try to hack the CodeUri attribute to point to the .aws-sam directory