You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When deploying a basic function to sandbox, the following error occurs:
"""
Failed to instantiate nodejs function construct
Caused By: Failed to bundle asset amplify-amplifyvitereacttemplate-<MY_SANDBOX>/function/test-function-lambda/Code/Stage, bundle output is located at <MY_PROJECT_FOLDER>amplify\artifacts\cdk.out\bundling-temp-49f5fc225f5f9c84d79ef6eb8c561146ce3a8f455642ad6758130b26a30884b3-error: Error: spawnSync cmd ENOENT
"""
Expected behavior
I am trying to implement the basic "hello world" exampl for implementing a custom function, as shown in the amplify gen2 docs.
It is expected that the "hello world" example, in a fresh Amplify template project, should successfully deploy the lambda function to the sandbox environment.
// amplify\functions\testFunction\handler.ts
import type { Schema } from '../../data/resource';
export const handler: Schema['testFunction']['functionHandler'] = async (
event,
) => {
const { name } = event.arguments;
return `Hello, ${name}!`;
};
// amplify\data\resource.ts
import { type ClientSchema, a, defineData } from '@aws-amplify/backend';
import { testFunction } from '../functions/testFunction/resource';
const schema = a.schema({
testFunction: a
.query()
.arguments({
name: a.string(),
})
.returns(a.string())
.handler(a.handler.function(testFunction))
.authorization((allow) => [allow.authenticated()])
});
export type Schema = ClientSchema<typeof schema>;
export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: 'userPool',
apiKeyAuthorizationMode: {
expiresInDays: 30,
},
},
});
Log output
[DEBUG] 2025-02-05T22:18:08.462Z: [Sandbox] Executing command `deploy`
[DEBUG] 2025-02-05T22:18:14.445Z: WARNING: owners may reassign ownership for the following model(s) and role(s): Quiz: [owner], QuizAttempt: [owner]. If this is not intentional, you may want to apply field-level authorization rules to these fields. To read more: https://docs.amplify.aws/cli/graphql/authorization-rules/#per-user--owner-based-data-access.
[DEBUG] 2025-02-05T22:18:14.507Z: Bundling asset amplify-amplifyvitereacttemplate-<MY_SANDBOX>/function/test-function-lambda/Code/Stage...
[DEBUG] 2025-02-05T22:18:14.517Z: <PROJECT_FOLDER>\node_modules\@aws-amplify\backend-function\src\factory.ts:454
throw new AmplifyUserError(
^
AmplifyError [NodeJSFunctionConstructInitializationError]: Failed to instantiate nodejs function construct
at new AmplifyFunction (<PROJECT_FOLDER>\node_modules\@aws-amplify\backend-function\src\factory.ts:454:13)
at FunctionGenerator.generateContainerEntry (<PROJECT_FOLDER>\node_modules\@aws-amplify\backend-function\src\factory.ts:362:12)
at SingletonConstructContainer.getOrCompute (<PROJECT_FOLDER>\node_modules\@aws-amplify\backend\src\engine\singleton_construct_container.ts:51:19)
at FunctionFactory.getInstance (<PROJECT_FOLDER>\node_modules\@aws-amplify\backend-function\src\factory.ts:191:31)
at <anonymous> (<PROJECT_FOLDER>\node_modules\@aws-amplify\backend\src\backend_factory.ts:117:68)
at Array.forEach (<anonymous>)
at new BackendFactory (<PROJECT_FOLDER>\node_modules\@aws-amplify\backend\src\backend_factory.ts:113:40)
at defineBackend (<PROJECT_FOLDER>\node_modules\@aws-amplify\backend\src\backend_factory.ts:157:19)
at <anonymous> (<PROJECT_FOLDER>\amplify\backend.ts:8:1)
at ModuleJob.run (node:internal/modules/esm/module_job:234:25) {
cause: Error: Failed to bundle asset amplify-amplifyvitereacttemplate-<MY_SANDBOX>/function/test-function-lambda/Code/Stage, bundle output is located at <PROJECT_FOLDER>\.amplify\artifacts\cdk.out\bundling-temp-49f5fc225f5f9c84d79ef6eb8c561146ce3a8f455642ad6758130b26a30884b3-error: Error: spawnSync cmd ENOENT
at AssetStaging.bundle (<PROJECT_FOLDER>\node_modules\aws-cdk-lib\core\lib\asset-staging.js:2:619)
at AssetStaging.stageByBundling (<PROJECT_FOLDER>\node_modules\aws-cdk-lib\core\lib\asset-staging.js:1:5297)
at stageThisAsset (<PROJECT_FOLDER>\node_modules\aws-cdk-lib\core\lib\asset-staging.js:1:2728)
at Cache.obtain (<PROJECT_FOLDER>\node_modules\aws-cdk-lib\core\lib\private\cache.js:1:242)
at new AssetStaging (<PROJECT_FOLDER>\node_modules\aws-cdk-lib\core\lib\asset-staging.js:1:3125)
at new Asset (<PROJECT_FOLDER>\node_modules\aws-cdk-lib\aws-s3-assets\lib\asset.js:1:1141)
at AssetCode.bind (<PROJECT_FOLDER>\node_modules\aws-cdk-lib\aws-lambda\lib\code.js:5:3487)
at new Function (<PROJECT_FOLDER>\node_modules\aws-cdk-lib\aws-lambda\lib\function.js:1:10003)
at new NodejsFunction (<PROJECT_FOLDER>\node_modules\aws-cdk-lib\aws-lambda-nodejs\lib\function.js:1:2111)
at new AmplifyFunction (<PROJECT_FOLDER>\node_modules\@aws-amplify\backend-function\src\factory.ts:430:24),
classification: 'ERROR',
options: {
message: 'Failed to instantiate nodejs function construct',
resolution: 'See the underlying error message for more details. Use `--debug` for additional debugging information.'
},
serializedError: '{"name":"NodeJSFunctionConstructInitializationError","classification":"ERROR","options":{"message":"Failed to instantiate nodejs function construct","resolution":"See the underlying error message for more details. Use `--debug` for additional debugging information."},"cause":{"name":"Error","message":"Failed to bundle asset amplify-amplifyvitereacttemplate-<MY_SANDBOX>/function/test-function-lambda/Code/Stage, bundle output is located at <PROJECT_FOLDER>\\\\.amplify\\\\artifacts\\\\cdk.out\\\\bundling-temp-49f5fc225f5f9c84d79ef6eb8c561146ce3a8f455642ad6758130b26a30884b3-error: Error: spawnSync cmd ENOENT"}}',
resolution: 'See the underlying error message for more details. Use `--debug` for additional debugging information.',
details: undefined,
link: undefined,
code: undefined
}
Node.js v20.18.2
[DEBUG] 2025-02-05T22:18:14.582Z: Subprocess exited with error 1
[DEBUG] 2025-02-05T22:18:15.437Z: {
"compilerOptions": {
"target": "es2022",
"module": "es2022",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"paths": {
"$amplify/*": [
"../.amplify/generated/*"
]
},
"allowSyntheticDefaultImports": true,
"resolvePackageJsonExports": true,
"resolvePackageJsonImports": true,
"useDefineForClassFields": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"strictBuiltinIteratorReturn": true,
"alwaysStrict": true,
"useUnknownInCatchVariables": true
},
"files": [
"./backend.ts",
"./auth/resource.ts",
"./data/resource.ts",
"./functions/testFunction/handler.ts",
"./functions/testFunction/resource.ts",
"./storage/resource.ts"
]
}
Failed to instantiate nodejs function construct
Caused By: Failed to bundle asset amplify-amplifyvitereacttemplate-<MY_SANDBOX>/function/test-function-lambda/Code/Stage, bundle output is located at <PROJECT_FOLDER>\\.amplify\\artifacts\\cdk.out\\bundling-temp-49f5fc225f5f9c84d79ef6eb8c561146ce3a8f455642ad6758130b26a30884b3-error: Error: spawnSync cmd ENOENT
Resolution: See the underlying error message for more details. Use `--debug` for additional debugging information.
[INFO] 2025-02-05T22:18:20.865Z: [Sandbox] Watching for file changes...
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered:
Hey @HuiSF, thank you for reaching out. Could provide us some information on how was node installed Node: 20.18.2 - C:\Program Files\nodejs\node.EXE and the terminal being used?
Additionally, could you try update the @aws-amplify/backend and @aws-amplify/backend-cli to the latest version and retry sandbox?
for example the latest versions are
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Not applicable
Amplify Version
v6
Amplify Categories
function
Backend
Amplify Gen 2
Environment information
Describe the bug
When deploying a basic function to sandbox, the following error occurs:
"""
Failed to instantiate nodejs function construct
Caused By: Failed to bundle asset amplify-amplifyvitereacttemplate-<MY_SANDBOX>/function/test-function-lambda/Code/Stage, bundle output is located at <MY_PROJECT_FOLDER>amplify\artifacts\cdk.out\bundling-temp-49f5fc225f5f9c84d79ef6eb8c561146ce3a8f455642ad6758130b26a30884b3-error: Error: spawnSync cmd ENOENT
"""
Expected behavior
I am trying to implement the basic "hello world" exampl for implementing a custom function, as shown in the amplify gen2 docs.
It is expected that the "hello world" example, in a fresh Amplify template project, should successfully deploy the lambda function to the sandbox environment.
Reproduction steps
npx ampx sandbox --debug
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: