I am following a tutorial in order to learn how to work with the serverless framework. The goal is to deploy a Django application. This tutorial suggests putting the necessary environment variables in a separate yml-file. Unfortunately, following the tutorial gets me a KeyError.
I have a serverless.yml, variables.yml and a handler.py. I will incert all code underneath, together with the given error.
serverless.yml:
service: serverless-django
custom: ${file(./variables.yml)}
provider:
name: aws
runtime: python3.8
functions:
hello:
environment:
- THE_ANSWER: ${self:custom.THE_ANSWER}
handler: handler.hello
variables.yml:
THE_ANSWER: 42
handler.py:
import os
def hello(event, context):
return {
"statusCode": 200,
"body": "The answer is: " + os.environ["THE_ANSWER"]
}
The error in my terminal:
{
"errorMessage": "'THE_ANSWER'",
"errorType": "KeyError",
"stackTrace": [
" File \"/var/task/handler.py\", line 7, in hello\n \"body\": \"The answer is: \" + os.environ[\"THE_ANSWER\"]\n",
" File \"/var/lang/lib/python3.8/os.py\", line 675, in __getitem__\n raise KeyError(key) from None\n"
]
}
Error --------------------------------------------------
Error: Invoked function failed
at AwsInvoke.log (/snapshot/serverless/lib/plugins/aws/invoke/index.js:105:31)
at AwsInvoke.tryCatcher (/snapshot/serverless/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/snapshot/serverless/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/snapshot/serverless/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/snapshot/serverless/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/snapshot/serverless/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/snapshot/serverless/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/snapshot/serverless/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/snapshot/serverless/node_modules/bluebird/js/release/async.js:102:5)
at Immediate._onImmediate (/snapshot/serverless/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (internal/timers.js:456:21)
at process.topLevelDomainCallback (domain.js:137:15)
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
Operating System: linux
Node Version: 12.18.1
Framework Version: 2.0.0 (standalone)
Plugin Version: 4.0.2
SDK Version: 2.3.1
Components Version: 3.1.2
The command i'm trying is 'sls invoke -f hello'. The command 'sls deploy' has been already executed succesfully.
I am new to serverless, so please let me know how to fix this, or if any more information is needed.
First of all, there is an error in yml script:
Serverless Error ---------------------------------------
Invalid characters in environment variable 0
The error is defining environment variables as an array instead of key-value pairs
And then after deployment, everything works smoothly (sls deploy -v)
sls invoke --f hello
{
"statusCode": 200,
"body": "The answer is: 42"
}
serverless.yml
service: sls-example
custom: ${file(./variables.yml)}
provider:
name: aws
runtime: python3.8
functions:
hello:
environment:
THE_ANSWER: ${self:custom.THE_ANSWER}
handler: handler.hello
variables.yml
THE_ANSWER: 42
I'm using the Kantu web automation tool for the first time. Most of it is intuitive, but I'm now encountering an error when looping through a CSV. The relevant part of my script is:
{
"Command": "echo",
"Target": "Found customer with email ${emailAddress}",
"Value": ""
},
{
"Command": "echo",
"Target": "Expected email name: ${!COL1}",
"Value": ""
},
{
"Command": "if",
"Target": "${emailAddress} == \"${!COL1}#domain.com\"",
"Value": ""
},
This produces the following log:
[info] Executing: | echo | Found customer with email ${emailAddress} | |
[echo] Found customer with email 70866223#domain.com
[info] Executing: | echo | Expected email name: ${!COL1} | |
[echo] Expected email name: 70866223
[info] Executing: | if | ${emailAddress} == "${!COL1}#domain.com" | |
[error] Error in runEval condition of if: Invalid or unexpected token
So you can see the variables ${emailAddress} and ${!COL1} are stored correctly, but my if condition is not evaluating correctly. I've also tried changing \"${!COL1}#domain.com\" to ${!COL1} + \"#domain.com\" with same result.
I assume this is something to do with escape characters or something, but I can't find anything related in the docs. Any pointers appreciated.
The if expression is handled like in storeEval. To quote from one of the storeEval examples in the docs :
x="${myvar}"; x.length;
Note that our variable ${myvar} is converted to a text string before the Javascript EVAL is executed. Therefore ${myvar} has to be inside "..." like any other text.
So I'd say the reason your code fails on the if is that your ${emailAddress} is not inside a String.
"${emailAddress}" == "${!COL1}#domain.com"
should work.
I'm facing an error when building my titanium appcelerator application for android, below are modules installed :
- modules
Android > com.pushwoosh.module and dk.napp.drawer
tiapp.xml
<modules>
<module platform="iphone">dk.napp.drawer</module>
<module platform="android">dk.napp.drawer</module>
...
When i build the app, and run it from device i get following error :
[ERROR] : TiExceptionHandler: (main) [60613,103255] ----- Titanium Javascript Runtime Error -----
[ERROR] : TiExceptionHandler: (main) [1,103256] - In ti:/module.js:303,2
[ERROR] : TiExceptionHandler: (main) [0,103256] - Message: Uncaught Error: Requested module not found: dk.napp.drawer
[ERROR] : TiExceptionHandler: (main) [0,103256] - Source: throw new Error("Requested module not found: " + request); // TODO Set 'code' property to 'MODULE_NOT_FOUND' to match Node?
[ERROR] : V8Exception: Exception occurred at ti:/module.js:303: Uncaught Error: Requested module not found: dk.napp.drawer
[ERROR] : ViewRootImpl: sendUserActionEvent() mView == null
So i don't know why the app doesn't found the dk.app.drawer module, here is a screenshot of all modules:
Thanks again for your helps
In the screenshot you only show the version 1.2.4 which is the iOS version. Did you add the android version too?
https://github.com/viezel/NappDrawer/tree/master/android/dist
Attempting to test msgpack as dependency in a simple release package using rebar in Erlang / OTP.
My folder structure is as follows
Project -> Apps -> myapp -> ebin
-> src
-> deps -> msgpack (folder)
-> rebar (exe)
-> rebar config
-> rel -> reltool.config
-> files (folder)
-> mynode (folder)
Code snippet of the function & its handle_call:
num_pokes() ->
gen_server:call(?MODULE, num_pokes).
handle_call(num_pokes, _From, State = #state{ num_pokes = PokeCount }) ->
MP = msgpack:pack(PokeCount),
io:format (" Message is packed : ~p~n", MP),
MuP = msgpack:unpack_stream(MP),
io:format (" Message is now UNpacked : ~p~n", MuP),
io:format (" Pokecount : ~p~n", PokeCount),
{reply, PokeCount, State};
Error showing: when num_pokes() is called
=ERROR REPORT==== 10-Apr-2015::12:44:53 ===
** Generic server myapp_server terminating
** Last message in was num_pokes
** When Server state == {state,2}
** Reason for termination ==
** {'module could not be loaded',
[{msgpack,pack,[2],[]},
{myapp_server,handle_call,3,[{file,"src/myapp_server.erl"},{line,32}]},
{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,607}]},
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,639}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]}
** exception exit: {{undef,
[{msgpack,pack,[2],[]},
{myapp_server,handle_call,3,
[{file,"src/myapp_server.erl"},{line,32}]},
{gen_server,try_handle_call,4,
[{file,"gen_server.erl"},{line,607}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,639}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]},
{gen_server,call,[myapp_server,num_pokes]}}
in function gen_server:call/2 (gen_server.erl, line 182)
Pass -pa deps/msgpack/ebin to erl as command-line arguments. Then it will find the compiled modules.
Folder structure pointing towards mspack was shown by me as ./deps (dependencies folder). It should be ./deps/msgpack
I've been fighting with Intern for quite a while, to test both server code (following these recommendations) and client code (tradionnal app, as defined on this project of mine, for example).
The Intern config file contains:
loader: {
packages: [
{ name: 'dojo', location: './libs/dojo' },
{ name: 'server', location: './server' }
]
},
However, the location of the dojo package is always ignored. The reported error is:
$ node node_modules/intern/client.js config=intern suites=server/model/tests/News
Defaulting to "console" reporter
Error: Failed to load module dojo/_base/declare from <root>/dojo/_base/declare.js (parent: server/model/Ne
ws)
at <root>\node_modules\intern\node_modules\dojo\dojo.js:742:12
at fs.js:207:20
at Object.oncomplete (fs.js:107:15)
I redacted for the <root> part to simplify the output.
My current workaround is to copy the dojo folder at the <root> level but that's inconvenient...
My current folder structure is:
<root>
|- client
|- libs
| |- dojo
| |- ...
|- node_modules
| |- grunt
| |- intern
| |- ...
|- server
|- dao
| |- tests
|- model
| |- tests
|- ...
Where am I wrong?
Update: Everywhere I read (like here), the configuration is specified as a MID, not as a filename with an extension. When I run my command with "config=intern.js" the configuration is correctly processed (I've hacked "client.js" to log the config content). Note: I'm running Node.js/Intern on a Windows machine...
Additional information: Here is the minimum content required to process my tests.
define({
loader: {
packages: [
{ name: 'dojo', location: './libs/dojo' },
{ name: 'server', location: './server' }
]
},
suites: [ 'server/allTests' ]
});
The issue I faced is related to the loader:
If the config file intern.js is at the root level, the command MUST contain the extension: config=intern.js;
If the config file is in a subfolder like tests then the extension MUST be omitted in the command: config=tests/intern.
This happens in intern/client.js, line 38, with the call to the Node.js require() function.