AWS Lambda Node.js 6.10 : "errorMessage": "Cannot find module 'cfn-response'", - node.js

I am trying to deploy a lambda function in Nodejs 6.10 and I am getting this error:
Response:
{
"errorMessage": "Cannot find module 'cfn-response'",
"errorType": "Error",
"stackTrace": [
"Module.require (module.js:497:17)",
"require (internal/module.js:20:19)",
"Object. (/var/task/index.js:2:20)",
"Module._compile (module.js:570:32)",
"Object.Module._extensions..js (module.js:579:10)",
"Module.load (module.js:487:32)",
"tryModuleLoad (module.js:446:12)",
"Function.Module._load (module.js:438:3)"
]
}
Function Logs:
START RequestId: d1123bc9-1722-11e8-84a2-c9cba9c66de8 Version: $LATEST
Unable to import module 'index': Error
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/index.js:2:20)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
END RequestId: d1123bc9-1722-11e8-84a2-c9cba9c66de8
REPORT RequestId: d1123bc9-1722-11e8-84a2-c9cba9c66de8 Duration: 87.34 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 32 MB
I am using Node.js 6.10 version for this method and did inline code edit.
Code I am trying to execute:
var response = require('cfn-response');
exports.handler = function(event, context) {
var input = parseInt(event.ResourceProperties.Input);
var responseData = {Value: input * 5};
response.send(event, context, response.SUCCESS, responseData);
};
Any clues?

Mostly it is because of the way zipping the files making the problem. Instead of zipping the root folder you have to select all files and zip it like below,
Please upload all files and subfolders like below. Please include node_modules folder as well in the zip.

Related

Imports from tsconfig paths not working with bazel: Cannot find module '#...'

Repo for reproduction: https://github.com/timothyaltemus/bazel-typescript-stackoverflow-example.
I am running into an issue where I am unable to use my tsconfig paths configuration for importing in my TypeScript files.
tsconfig.json:
{
...
"compilerOptions": {
"baseUrl": ".",
"paths" {
"#*": [
".",
"bazel-out/darwin-fastbuild/bin/*",
"bazel-out/k8-fastbuild/bin/*",
"bazel-out/x64_windows-fastbuild/bin/*",
"bazel-out/darwin-dbg/bin/*",
"bazel-out/k8-dbg/bin/*",
"bazel-out/x64_windows-dbg/bin/*"
]
},
"rootDirs": [
".",
"bazel-out/darwin-fastbuild/bin/",
"bazel-out/k8-fastbuild/bin/",
"bazel-out/x64_windows-fastbuild/bin/",
"bazel-out/darwin-dbg/bin/",
"bazel-out/k8-dbg/bin/",
"bazel-out/x64_windows-dbg/bin/"
]
...
}
...
}
Folder Structure:
apps
server
services
BUILD
hello_service.ts
BUILD
index.ts
libs
a_lib
BUILD
do_a.ts
b_lib
BUILD
do_b.ts
c_lib
BUILD
do_c.ts
Build
tsconfig.json
index.ts:
...
import { doToC } from '#libs/c_lib/do_c';
import {
HelloService,
HelloServiceImpl,
} from '#apps/server/services/hello_service';
...
Full Stacktrace:
INFO: Analyzed target //apps/server:server (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //apps/server:server up-to-date:
bazel-bin/apps/server/server.sh
bazel-bin/apps/server/server_loader.js
bazel-bin/apps/server/server_require_patch.js
INFO: Elapsed time: 1.994s, Critical Path: 0.03s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Error: Cannot find module '#libs/c_lib/do_c'
Require stack:
- /home/tim/.cache/bazel/_bazel_tim/4d04e993ef8ae996d277978eb4eab582/execroot/typescript/bazel-out/k8-fastbuild/bin/apps/server/server.sh.runfiles/typescript/apps/server/index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (home/tim/.cache/bazel/_bazel_tim/4d04e993ef8ae996d277978eb4eab582/execroot/typescript/bazel-out/k8-fastbuild/bin/apps/apps/server/index.ts:4:1)
at Module._compile (node:internal/modules/cjs/loader:1099:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
Please see the example repo for an example of how to reproduce this error.

Semantic-release - Error: Cannot find module '../output'

No matter what I do I always get exactly the same error when I run command 'npx semantic-release --debug
' in BitBucket pipelines. Dry-run seems to run fine.
Thing I have already tried:
reinstall node modules
update packages
copy exactly the same configuration/packages from project with
working semantic-release
All the files are definitely there. Maybe it can't access?
here is a full debug report:
npx: installed 746 in 16.856s
[5:36:26 PM] [semantic-release] › ℹ Running semantic-release version 17.1.1
2020-06-25T17:36:26.883Z semantic-release:config load config from: /opt/atlassian/pipelines/agent/build/package.json
2020-06-25T17:36:26.887Z semantic-release:config options values: {
branches: [ 'master', 'develop' ],
repositoryUrl: 'git#$NEXUS_USERNAME.org:acurable/acupebble-g2-firmware.git',
tagFormat: 'v${version}',
plugins: [
[ '#semantic-release/commit-analyzer', [Object] ],
[ '#semantic-release/npm', [Object] ],
[ '#semantic-release/release-notes-generator', [Object] ],
'#semantic-release/changelog',
'#semantic-release/git'
],
_: [],
debug: true,
'$0': '/root/.npm/_npx/52/bin/semantic-release'
}
[5:36:27 PM] [semantic-release] › ✖ An error occurred while running semantic-release: Error: Cannot find module '../output'
Require stack:
- /opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/output-json.js
- /opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/index.js
- /opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/index.js
- /opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/lib/prepare.js
- /opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/index.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/utils.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/index.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/lib/get-config.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/index.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/cli.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/bin/semantic-release.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:952:15)
at Function.Module._load (internal/modules/cjs/loader.js:835:27)
at Module.require (internal/modules/cjs/loader.js:1012:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/output-json.js:4:24)
at Module._compile (internal/modules/cjs/loader.js:1123:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
at Module.load (internal/modules/cjs/loader.js:972:32)
at Function.Module._load (internal/modules/cjs/loader.js:872:14)
at Module.require (internal/modules/cjs/loader.js:1012:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/output-json.js',
'/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/index.js',
'/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/index.js',
'/opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/lib/prepare.js',
'/opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/index.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/utils.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/index.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/lib/get-config.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/index.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/cli.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/bin/semantic-release.js'
]
}
Error: Cannot find module '../output'
Require stack:
- /opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/output-json.js
- /opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/index.js
- /opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/index.js
- /opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/lib/prepare.js
- /opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/index.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/utils.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/index.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/lib/get-config.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/index.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/cli.js
- /root/.npm/_npx/52/lib/node_modules/semantic-release/bin/semantic-release.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:952:15)
at Function.Module._load (internal/modules/cjs/loader.js:835:27)
at Module.require (internal/modules/cjs/loader.js:1012:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/output-json.js:4:24)
at Module._compile (internal/modules/cjs/loader.js:1123:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
at Module.load (internal/modules/cjs/loader.js:972:32)
at Function.Module._load (internal/modules/cjs/loader.js:872:14)
at Module.require (internal/modules/cjs/loader.js:1012:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/output-json.js',
'/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/json/index.js',
'/opt/atlassian/pipelines/agent/build/node_modules/fs-extra/lib/index.js',
'/opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/lib/prepare.js',
'/opt/atlassian/pipelines/agent/build/node_modules/#semantic-release/changelog/index.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/utils.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/lib/plugins/index.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/lib/get-config.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/index.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/cli.js',
'/root/.npm/_npx/52/lib/node_modules/semantic-release/bin/semantic-release.js'
]
2020-06-25T17:36:27.964997083Z stderr P }
This is crazy.
Just realised that I had this line in gitIgnore.txt: **/Output
In my local repository all the files were there but index.js was missing since all files in any **/Output path would not be included.
Will never use global gitIgnore again.

The "amdefine" can not load a custom module

I installed the requirejs package to optimize the work with paths to files. In general, I do the next steps:
I have an object with paths to file, that have next values:
"app/database": "/home/dmitry/projects/information-platform-api/app/utils/database"
After I initialize the requirejs mapping in app.js (main file):
requirejs.config({
baseUrl: __dirname,
nodeRequire: require,
paths: paths,
map: {
'*': paths
}
});
After, I need to initialize base models, and with help for I called all files from paths object. This looks like:
for (let file in paths) {
requirejs(paths[file]);
}
When I initializing the file, which has the dependency of the above "app/database", I have a message error: Error: Cannot find module 'app/database'.
Maybe, I don't understand "How works the amdefine", but I have opinion, what a requirejs and amdefine don`t link. Do you have any ideas, why it doesn't work?
A part of the file, which need to investigate:
if (typeof define !== 'function') {
var define = require('amdefine')(module);
}
define([
'sequelize',
'app/database',
'model/student'
], (
Sequelize,
sequelize,
Student
) => { });
Result of my investigation:
The amdefine doesn't know about requirejs mapping.
Full error message:
Error: Tried loading "/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company" at /home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company then tried node's require("/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company") and it failed with error: Error: Cannot find module 'app/database'
Require stack:
- /home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company.js
- /home/dmitry/projects/information-platform-api/app.js
- /home/dmitry/projects/information-platform-api/bin/www
at /home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:2600:27
at Object.execCb (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1946:33)
at Module.check (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1133:51)
at Module.enable (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1426:22)
at Object.enable (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1807:39)
at Function.req.get (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:2524:33)
at Object.localRequire [as require] (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1678:40)
at requirejs (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:2047:24)
at Object.<anonymous> (/home/dmitry/projects/information-platform-api/app.js:142:5)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/home/dmitry/projects/information-platform-api/bin/www:7:13)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
originalError: Error: Cannot find module 'app/database'
Require stack:
- /home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company.js
- /home/dmitry/projects/information-platform-api/app.js
- /home/dmitry/projects/information-platform-api/bin/www
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at req (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:144:31)
at stringRequire (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:220:28)
at amdRequire (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:113:24)
at /home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:177:24
at Array.map (<anonymous>)
at runFactory (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:176:25)
at define (/home/dmitry/projects/information-platform-api/node_modules/amdefine/amdefine.js:277:13)
at Object.<anonymous> (/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company.js:5:1)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at /home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:2598:75
at Object.execCb (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1946:33)
at Module.check (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1133:51)
at Module.enable (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1426:22)
at Object.enable (/home/dmitry/projects/information-platform-api/node_modules/requirejs/bin/r.js:1807:39) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company.js',
'/home/dmitry/projects/information-platform-api/app.js',
'/home/dmitry/projects/information-platform-api/bin/www'
]
},
moduleName: '/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company',
requireModules: [
'/home/dmitry/projects/information-platform-api/app/code/IndividualScheduling/model/entity/Company'
]
}
Process finished with exit code 1
The solution is here guys. The amdefine have two params, first param it's a global variable module, and the second it's require function for calling the local files. By default, it was just require not requirejs which contains custom mapping.
if (typeof define !== 'function') {
var define = require('amdefine')(module, require('requirejs'));
}

installing with NPM gives out error:2406C06E:random number generator

I'm using Ubuntu server 18.04.
Every time I try to use NPM it crashes and shows the following exception:
internal/crypto/random.js:119
if (ex) throw ex;
^
Error: error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy
at Object.randomBytes (internal/crypto/random.js:54:31)
at /usr/lib/node_modules/npm/lib/npm.js:444:32
at Object.<anonymous> (/usr/lib/node_modules/npm/lib/npm.js:496:3)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at /usr/lib/node_modules/npm/bin/npm-cli.js:28:13 {
opensslErrorStack: [
'error:2406B072:random number generator:RAND_DRBG_generate:in error state',
'error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy',
'error:2406B072:random number generator:RAND_DRBG_generate:in error state',
'error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy'
]
}
Does anybody has any idea of what could be wrong?

Cannot find module 'ask-sdk' AND Unable to import module 'index' when packaged with Alexa CLI

Why is my skill not working? It was made with the Alexa CLI, but I get multiple errors in cloudwatch:
"errorMessage": "Cannot find module 'ask-sdk'",
"errorType": "Error",
"stackTrace": [
"Object.<anonymous> (/var/task/index.js:6:15)",
"Module._compile (module.js:652:30)",
"Object.Module._extensions..js (module.js:663:10)",
"Module.load (module.js:565:32)",
"tryModuleLoad (module.js:505:12)",
"Function.Module._load (module.js:497:3)"
]
}
START RequestId: 8d7ecc70-7308-11e8-a831-fd4af108282c Version: $LATEST
Unable to import module 'index': Error
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/index.js:6:15)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
END RequestId: 8d7ecc70-7308-11e8-a831-fd4af108282c
REPORT RequestId: 8d7ecc70-7308-11e8-a831-fd4af108282c Duration: 1.47 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 47 MB
Alexa CLI Says everything was packaged with no errors:
C:\Windows\System32\Premium_GlobalWarmingFacts>ask deploy
-------------------- Update Skill Project --------------------
Skill Id: amzn1.ask.skill.xxxxxxxxxxxxx
Skill deployment finished.
Model deployment finished.
Lambda deployment finished.
Lambda function(s) updated:
[URI] arn:aws:lambda:us-east-1:xxxxxxxxxx:ask-custom-Premium_GlobalWarmingFacts-default
In-skill product deployment finished.
In-skill product(s) updated:
[ID] amzn1.adg.product.3e8c2107-29b7-4976-86aa-5b140bfeb9fb [FILE] isps\entitlement\globalwarming_pack.json
[ID] amzn1.adg.product.fe25638b-5806-4782-95bc-281020966118 [FILE] isps\entitlement\history_pack.json
[ID] amzn1.adg.product.186a8b85-0c7e-4d53-99e7-fc19c661c0e2 [FILE] isps\entitlement\animals_pack.json
[ID] amzn1.adg.product.3334840f-209b-49f0-b713-06de28f35797 [FILE] isps\subscription\all_access.json
Your skill is now deployed and enabled in the development stage.
Try invoking the skill by saying “Alexa, open {your_skill_invocation_name}” or simulate an invocation via the `ask simulate` command.
Here are the file directories: file directory image
.ask
--config
isps
--entitlement
--subscription
lambda
--custom
models
--En-us.JSON
Please help! Thank you so much!

Resources