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

Bug: sam init with nodejs + typescript generate code which can't run local start-api #7845

Closed
josser opened this issue Jan 23, 2025 · 1 comment
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Comments

@josser
Copy link

josser commented Jan 23, 2025

Description:

I'm trying to run sam local start-api with node+typescript code. And turns out even if I use code from generated hello-world example it can't run.

Steps to reproduce:

sam init

You can preselect a particular runtime or package type when using the sam init experience.
Call sam init --help to learn more.

Which template source would you like to use?
1 - AWS Quick Start Templates
2 - Custom Template Location
Choice: 1

Choose an AWS Quick Start application template
1 - Hello World Example
2 - Data processing
3 - Hello World Example with Powertools for AWS Lambda
4 - Multi-step workflow
5 - Scheduled task
6 - Standalone function
7 - Serverless API
8 - Infrastructure event management
9 - Lambda Response Streaming
10 - GraphQLApi Hello World Example
11 - Full Stack
12 - Lambda EFS example
13 - Serverless Connector Hello World Example
14 - Multi-step workflow with Connectors
15 - DynamoDB Example
16 - Machine Learning
Template: 1

Use the most popular runtime and package type? (python3.13 and zip) [y/N]:

Which runtime would you like to use?
1 - dotnet8
2 - dotnet6
3 - go (provided.al2)
4 - go (provided.al2023)
5 - graalvm.java11 (provided.al2)
6 - graalvm.java17 (provided.al2)
7 - java21
8 - java17
9 - java11
10 - java8.al2
11 - nodejs22.x
12 - nodejs20.x
13 - nodejs18.x
14 - python3.9
15 - python3.8
16 - python3.13
17 - python3.12
18 - python3.11
19 - python3.10
20 - ruby3.3
21 - ruby3.2
22 - rust (provided.al2)
23 - rust (provided.al2023)
Runtime: 13

What package type would you like to use?
1 - Zip
2 - Image
Package type: 1

Based on your selections, the only dependency manager available is npm.
We will proceed copying the template using npm.

Select your starter template
1 - Hello World Example
2 - Hello World Example TypeScript
Template: 2

Would you like to enable X-Ray tracing on the function(s) in your application? [y/N]:

Would you like to enable monitoring using CloudWatch Application Insights?
For more info, please view https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-application-insights.html [y/N]:

Would you like to set Structured Logging in JSON format on your Lambda functions? [y/N]:

Project name [sam-app]:

-----------------------
Generating application:
-----------------------
Name: sam-app
Runtime: nodejs18.x
Architectures: x86_64
Dependency Manager: npm
Application Template: hello-world-typescript
Output Directory: .
Configuration file: sam-app/samconfig.toml

cd sam-app
~/Projects/sam-test/sam-app sam local start-api --port 5000

Observed result:

No current session found, using default AWS::AccountId
Initializing the lambda functions containers.
Local image is up-to-date
Using local image: public.ecr.aws/lambda/nodejs:18-rapid-x86_64.

Mounting /Users/josser/Projects/sam-test/sam-app/hello-world as /var/task:ro,delegated, inside runtime container
Containers Initialization is done.
Mounting HelloWorldFunction at http://127.0.0.1:5000/hello [GET]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. If you
used sam build before running local commands, you will need to re-run sam build for the changes to be picked up. You only need to restart SAM CLI if you update your AWS SAM template
2025-01-23 13:35:55 WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.

  • Running on http://127.0.0.1:5000
    2025-01-23 13:35:55 Press CTRL+C to quit
    Invoking app.lambdaHandler (nodejs18.x)
    Reuse the created warm container for Lambda function 'HelloWorldFunction'
    Lambda function 'HelloWorldFunction' is already running
    START RequestId: a0dd347c-b5a4-4199-8dea-3242f90e0e68 Version: $LATEST
    2025-01-23T11:36:01.126Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'app'\nRequire stack:\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'app'","Require stack:","- /var/runtime/index.mjs"," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)"," at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)"," at async start (file:///var/runtime/index.mjs:1282:23)"," at async file:///var/runtime/index.mjs:1288:1"]}
    23 Jan 2025 11:36:01,232 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 129 InvokeID=
    23 Jan 2025 11:36:01,248 [ERROR] (rapid) Invoke failed error=Runtime exited with error: exit status 129 InvokeID=a7cbd377-2a67-4651-9d8b-8837110f632a
    23 Jan 2025 11:36:01,249 [ERROR] (rapid) Invoke DONE failed: Sandbox.Failure

Expected result:

Hello world is executed

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: MacOS 15.2
  2. sam --version: SAM CLI, version 1.132.0
  3. AWS region: paris
sam --info                                                                                                                      
{
  "version": "1.132.0",
  "system": {
    "python": "3.13.1",
    "os": "macOS-15.2-arm64-arm-64bit-Mach-O"
  },
  "additional_dependencies": {
    "docker_engine": "27.4.0",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}
@josser josser added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Jan 23, 2025
@josser josser closed this as completed Jan 23, 2025
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

No branches or pull requests

1 participant