Unable to invoke aws lambda locally using sls - aws-lambda

Im using sls framework to launch my code and it was working fine until today.
serverless.yml's configuration wasnt modified and ive tried reinstalling sls but nothing seems to work.
The following message occurs for all my repos after throwing the following command:
sls invoke local -f function_name --accountId $accountId
Error message:
TypeError: Cannot read property 'Fn::ImportValue' of undefined
at /usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:188:22
at Array.map (<anonymous>)
at /usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:187:53
at tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
at Function.Promise.attempt.Promise.try (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/method.js:39:29)
at AwsInvokeLocal.loadEnvVars (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:154:25)
at AwsInvokeLocal.tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:456:21)
at process.topLevelDomainCallback (domain.js:137:15)```

Fixed by specifying the stage
I encountered the same issue and resolved it by specifying the stage with -s <STAGE> when executing sls invoke local.
Why this worked for me
I'm using serverless-dotenv-plugin, which lets me split my .env files by stage like so:
.env.dev
.env.test
.env.prod
Adding the stage helps specify which .env file to use with your local invocation. Without it, Serverless was trying to import .env with no stage appended, which doesn't exist on my project.

I was experiencing the same issue as well. It turns out that the latest version of Serverless seems to have bug. Downgrading to a previous version of sls fixed mine. I downgraded to verion 1.80, and it works fine now.

I figured out what's wrong. There was a warning while the invocation was running:
Serverless Warning --------------------------------------
A valid environment variable to satisfy the declaration 'env:MY_API_KEY' could not be found.
Since it was a warning I just ignored it and it previously worked but apparently the framework doesnt like it now. Dealing with the warning either by removing the variable or defining it resolved my issue.

For me all the environment variables had to be initialized for resolving error.
Serverless Warning --------------------------------------
A valid environment variable to satisfy the declaration 'env:<variable>' could not be found.
So I did this -
export <variable>=""

I got stuck with this issue as well. The reason is the environment variables defined in serverless.yml was not in the local .env file.
name: ...
handler: ...
environment:
API_KEY: ${env:API_KEY}
STAGE: ${self:provider.stage}
Here, API_KEY and STAGE should exist in .env.

Related

Yarn add - Private package - 404 Not Found

I want to install a private package hosted on an internal Gitlab with Yarn.
So, I configured my .npmrc with this informations :
#mypackage:registry=https://gitlab.intra/api/v4/packages/npm/
//gitlab.intra/api/v4/projects/819/packages/npm/:_authToken=xxxxx
//gitlab.intra/api/v4/packages/npm/:_authToken=xxxxx
always-auth=true
When I attempt to install the package with yarn add #mypackage/lib-node-client, Yarn give me an error :
Trace:
Error: https://gitlab.intra/api/v4/projects/725/packages/npm/#mypackage/lib-node-common/-/#mypackage/lib-node-common-21.7.1.tgz: Request failed "404 Not Found"
at ResponseError.ExtendableBuiltin (/usr/lib/node_modules/yarn/lib/cli.js:696:66)
at new ResponseError (/usr/lib/node_modules/yarn/lib/cli.js:802:124)
at Request.<anonymous> (/usr/lib/node_modules/yarn/lib/cli.js:67062:16)
at Request.emit (node:events:369:20)
at Request.module.exports.Request.onRequestResponse (/usr/lib/node_modules/yarn/lib/cli.js:141640:10)
at ClientRequest.emit (node:events:369:20)
at HTTPParser.parserOnIncomingClient (node:_http_client:646:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:129:17)
at HTTPParser.execute (<anonymous>)
at TLSSocket.socketOnData (node:_http_client:512:22)
So, Yarn can't find the URL : https://gitlab.intra/api/v4/projects/725/packages/npm/#mypackage/lib-node-common/-/#mypackage/lib-node-common-21.7.1.tgz
If I try to get this on my browser, I can download the package...
If anyone can help me please, thank's for all :)
In your .npmrc file, you tell how to connect to GitLab for the project 819. The error is about the project 725. GitLab simply refuse the connexion.
Try with
#mypackage:registry=https://gitlab.intra/api/v4/packages/npm/
//gitlab.intra/api/v4/projects/725/packages/npm/:_authToken=xxxxx
//gitlab.intra/api/v4/projects/819/packages/npm/:_authToken=xxxxx
//gitlab.intra/api/v4/packages/npm/:_authToken=xxxxx
always-auth=true
We had a gitlab private package registry, and was constantly getting this error.
npm i #placeholder/package-name works fine, but yarn add #placeholder/package-name was giving 404 errors.
I tried all possible solutions listed on this thread. At last, there was a section in gitlab on troubleshooting yarn installation [1].
It said,
try adding this to your .npmrc file (and replace <your_token> with your personal access token or deploy token):
//gitlab.example.com/api/v4/projects/:_authToken=<your_token>
Our previous .npmrc looked like this
save-exact=true
unsafe-perm=true
#placeholder:registry=https://gitlab.com/api/v4/packages/npm/
//gitlab.com/api/v4/packages/npm/:_authToken=${PLACEHOLDER_TOKEN}
With the above new line addition, it looked like this,
save-exact=true
unsafe-perm=true
#placeholder:registry=https://gitlab.com/api/v4/packages/npm/
//gitlab.com/api/v4/packages/npm/:_authToken=${PLACEHOLDER_TOKEN}
//gitlab.com/api/v4/projects/:_authToken=${PLACEHOLDER_TOKEN}
With that addition, yarn add #placeholder/package-name worked fine.
[1] https://docs.gitlab.com/ee/user/packages/npm_registry/#error-running-yarn-with-the-package-registry-for-npm-registry
This should be the accepted answer. //gitlab.com/api/v4/projects/:_authToken=${PLACEHOLDER_TOKEN} Was the piece I was missing, which supercedes needing to list each project id as in Joel's answer.

serverless - Type Error: Cannot read property 'Properties' of undefined

When issuing serverless deploy --region eu-central-1, I get the error
Type Error ---------------------------------------------
Cannot read property 'Properties' of undefined
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
This error only started after including
plugins:
- serverless-iam-roles-per-function
and can be reverted by commenting the plugin out. But I would like to use it for giving my lambda access to a DynamoDB.
The internet is pretty void about this error besides this typo. The error is not solved by a recent update (yet) and the notice of serverless doesn't help much. set SLS_DEBUG=*" before deployment yields:
Type Error ----------------------------------------------
TypeError: Cannot read property 'Properties' of undefined
at ServerlessIamPerFunctionPlugin.createRoleForFunction (C:\Users\XXXXX\MyProject\node_modules\serverless-iam-roles-per-function\dist\lib\index.js:273:25)
at ServerlessIamPerFunctionPlugin.createRolesPerFunction (C:\Users\XXXXX\MyProject\node_modules\serverless-iam-roles-per-function\dist\lib\index.js:383:18)
at PluginManager.invoke (C:\snapshot\serverless\lib\classes\PluginManager.js:579:20)
at async PluginManager.spawn (C:\snapshot\serverless\lib\classes\PluginManager.js:601:5)
at async Object.before:deploy:deploy [as hook] (C:\snapshot\serverless\lib\plugins\deploy.js:60:11)
at async PluginManager.invoke (C:\snapshot\serverless\lib\classes\PluginManager.js:579:9)
at async PluginManager.run (C:\snapshot\serverless\lib\classes\PluginManager.js:639:7)
at async Serverless.run (C:\snapshot\serverless\lib\Serverless.js:452:5)
at async C:\snapshot\serverless\scripts\serverless.js:751:9
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Should I iunclude my serverless.yml in this post? It's quite large.
Using some different key words I retrieved a second (!) online search result, quoting:
The plugin doesn't support working with the role property. You have the following in your provider sections: role: arn-for-deployment-role'. Try removing this.
More info here
This basically solves the issue and serverless-iam-roles-per-function worked after commenting out this:
provider:
name: aws
runtime: python3.7
#iam:
# role: CallsTableQueryRole
The reason for this could be, that previos versions (serverless < v2.24.0) used a different syntax than current ones. Compare:
provider:
#previously:
iam:
role:
statements:
#≥ v2.24.0
iamRoleStatements:
If you're using Bref framework make sure to update bref in composer and serverless globally to the latest version

Serverless Deploy crashing for ruby app using serverless-ruby-package on mac

I am using serverless for building aws app on a mac. When I do not use the "serverless-ruby-package" and deploy, I get
"errorMessage": "cannot load such file -- curb",
as the gems are not properly compiled.
The moment I add
plugins:
- serverless-ruby-package
and execute
sls deploy
or
sls package
I get
Type Error ----------------------------------------------
TypeError: Cannot read property 'push' of undefined
at PackageRubyBundlePlugin.beforePackage (/Users/xxxxxx/node_modules/serverless-ruby-package/index.js:85:45)
at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:576:20)
at async PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:634:7)
at async Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:327:5)
at async /usr/local/lib/node_modules/serverless/scripts/serverless.js:704:9
This looks to be a bug with the serverless-ruby-package plugin, as it's been reported by other users
You may consider adding a comment here.

What causes this webpack code 2 error and how to solve it?

Cannot even build in sidekick after a simple change
I created a new Core/TS project in Sidekick, I built the app and developed some stuff, but later I changed the icon to a nicer one (which requires a new build, no HMR for this type of change obviously), now I cannot build my app (cloud build, because I don't have Android Studio).
I checked the /main/assets/app/ and the icons were successfully changed there and they were existed.
What is happening? How do I fix this big issue? My patience bottle with all these critical errors even after simple changes is getting emptied.
I also tried "removing .cloud and folder directories", and clicking "clean cloud processes", adding "clean" option, etc...
But none worked.
I also updated the webpack.config.js file, with node_modules.bin\update-ns-webpack --configs
The file got successfully updated, but still did not solve the problem and I still cannot build.
Still after many hours cannot cloud build my app in sidekick. I also tried tns platform remove android, tns install, etc, etc... none worked out.
this is the error message:
[00:00:18.521] [WARN] Executing webpack failed with exit code 2.
[00:00:18.681] [ERROR] clean-webpack-plugin: /mnt/storage/builds/_/af8fe992d35e76b54f5523261a83dac973ffc9ed/5.3.4/5.3.1/Spread/platforms/android/app/src/main/assets/app/**/* has been removed.
Executing webpack failed with exit code 2.
'Build failed with error code 2'.
[19-06-10 19:13:56.767] Couldn't enable debugging for EP7333JKFA, Error: Couldn't enable debugging for EP7333JKFA
at Errors.fail (C:\Users\Bridge\AppData\Roaming\npm\node_modules\nativescript\lib\common\errors.js:126:28)
at Errors.failWithoutHelp (C:\Users\Bridge\AppData\Roaming\npm\node_modules\nativescript\lib\common\errors.js:136:21)
at LiveSyncService.<anonymous> (C:\Users\Bridge\AppData\Roaming\npm\node_modules\nativescript\lib\services\livesync\livesync-service.js:253:30)
at Generator.next (<anonymous>)
at C:\Users\Bridge\AppData\Roaming\npm\node_modules\nativescript\lib\services\livesync\livesync-service.js:13:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\Bridge\AppData\Roaming\npm\node_modules\nativescript\lib\services\livesync\livesync-service.js:9:12)
at LiveSyncService.enableDebuggingCoreWithoutWaitingCurrentAction (C:\Users\Bridge\AppData\Roaming\npm\node_modules\nativescript\lib\services\livesync\livesync-service.js:250:16)
at LiveSyncService.enableDebuggingCoreWithoutWaitingCurrentAction (C:\Users\Bridge\AppData\Roaming\npm\node_modules\nativescript\lib\common\decorators.js:67:47)
at LiveSyncService.<anonymous> (C:\Users\Bridge\AppData\Roaming\npm\node_modules\nativescript\lib\services\livesync\livesync-service.js:290:25)
at Generator.next (<anonymous>)
at fulfilled (C:\Users\Bridge\AppData\Roaming\npm\node_modules\nativescript\lib\services\livesync\livesync-service.js:10:58)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
OUTPUT 2
EDIT:
SOLVED
https://github.com/NativeScript/sidekick-feedback/issues/384#issuecomment-508028462
I know this isn't an answer, but it is happening to me, too. I am running Nativescript 5.4.1. I can build with webpack, but as soon as I try to run with AOT or Uglify, I can't build and the error message isn't very helpful.
Try to remove and add 'nativescript-dev-webpack'-plugin using nativescript-sidekick-GUI, this resolve my issue...

Cannot run in production mode

I have a donejs application and its running ok in development mode donejs develop, but when I run it in production mode:
donejs build
donejs deploy (to firebase)
NODE_ENV=production donejs start
it will not start and show an error (see CODE A)
This file: file:my-app/dist/bundles/my-app/index.js:704 corresponds to JQuery 3.x and its not a dependency of the project itself but a dependency of can-connect-feathers (https://github.com/canjs/can-connect-feathers). In fact in index.js there is also included JQuery 2.x what makes me think there might be some sort of incompatibility among them.
I already tried changing the project's dependency to JQuery 3.x but didn't help. Actually it will make even donejs develop fail (see CODE B).
I also tried the following:
cd my-app/node_modules/steal
npm install
but didn't help, another error appears and finally tried cd my-app/node_modules/can && npm install but that end up in multiple errors.
I'm using:
donejs#0.9.2
node#4.6.2
npm#2.15.11
can-connect-feathers#1.2.1
CODE A
NODE_ENV=production donejs start
my-app#0.0.0 start my-app
done-serve --proxy http://localhost:3030 --port 8080
done-serve starting on http://localhost:8080
Potentially unhandled rejection [5] TypeError: Error loading "package.json!npm" at file:my-app/package.json
Error loading "bundles/my-app/index" at file:my-app/dist/bundles/my-app/index.js
Error evaluating file:my-app/dist/bundles/my-app/index.js
Cannot read property 'createElement' of undefined
at i (file:my-app/dist/bundles/my-app/index.js:704:20)
at file:my-app/dist/bundles/my-app/index.js:1039:2881
at file:my-app/dist/bundles/my-app/index.js:1039:3580
at file:my-app/dist/bundles/my-app/index.js:268:21
at file:my-app/dist/bundles/my-app/index.js:268:27
at Object.exports.runInThisContext (vm.js:54:17)
at doEval (my-app/node_modules/steal/node_modules/steal-systemjs/dist/system.src.js:2059:10)
at __eval (my-app/node_modules/steal/node_modules/steal-systemjs/dist/system.src.js:1976:7)
at Loader.exec [as __exec] (my-app/node_modules/steal/node_modules/steal-systemjs/dist/system.src.js:339:5)
at Loader.loader.instantiate (my-app/node_modules/steal/node_modules/steal-systemjs/dist/system.src.js:1517:16)
CODE B
donejs develop
my-app#0.0.0 develop my-app
done-serve --develop --proxy http://localhost:3030 --port 8080
done-serve starting on http://localhost:8080
Potentially unhandled rejection [8] Error: Error loading "my-app#0.0.0#index.stache!done-autorender#0.8.0#autorender" at <unknown>
Error loading "can#2.3.27#util/jquery/jquery" at file:my-app/node_modules/can/util/jquery/jquery.js
Error loading "can#2.3.27#util/jquery/jquery" from "done-autorender#0.8.0#autorender" at file:my-app/node_modules/done-autorender/src/autorender.js
Did not find ./node_modules/can/node_modules/jquery/package.json
at FetchTask.utils.extend.next (file:my-app/node_modules/steal/ext/npm-crawl.js:532:11)
at file:my-app/node_modules/steal/ext/npm-crawl.js:556:33
at tryCatchReject (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:1183:30)
at runContinuation1 (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:1142:4)
at Fulfilled.when (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:930:4)
at Pending.run (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:821:13)
at Scheduler._drain (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:97:19)
at Scheduler.drain (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:62:9)
at nextTickCallbackWith0Args (node.js:436:9)
at process._tickCallback (node.js:365:13)
Potentially unhandled rejection [16] Error: Error loading "can#2.3.27#util/jquery/jquery" at file:my-app/node_modules/can/util/jquery/jquery.js
Error loading "can#2.3.27#util/jquery/jquery" from "my-app#0.0.0#index.stache!done-autorender#0.8.0#autorender" at file:my-app/src/index.stache
Did not find ./node_modules/can/node_modules/jquery/package.json
at FetchTask.utils.extend.next (file:my-app/node_modules/steal/ext/npm-crawl.js:532:11)
at file:my-app/node_modules/steal/ext/npm-crawl.js:556:33
at tryCatchReject (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:1183:30)
at runContinuation1 (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:1142:4)
at Fulfilled.when (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:930:4)
at Pending.run (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:821:13)
at Scheduler._drain (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:97:19)
at Scheduler.drain (my-app/node_modules/steal/node_modules/steal-systemjs/node_modules/steal-es6-module-loader/dist/es6-module-loader.src.js:62:9)
at nextTickCallbackWith0Args (node.js:436:9)
at process._tickCallback (node.js:365:13)
If the double jQuery installation is the issue, it should be resolved by version 2.0.0, which is exactly the same as the 1.0 version, but requires that you pass in a jQuery package as the jquery option. So, in addition to whatever else you had in your can-connect-feathers config, you'll need to provide the jquery option:
import $ from 'jquery'
import Feathers from 'can-connect-feathers';
new Feathers({
jquery: $
});

Resources