I tried to invoke lambda function with Amazon RDS Postgres database. I got this error, when I tried to run the lambda function:
{
"errorMessage": "Unable to import module 'lambda_function': No module named'psycopg2._psycopg'",
"errorType": "Runtime.ImportModuleError",
"requestId": "c1c7e814-9560-4d5e-a71d-fa39fc33132e",
"stackTrace": []
}
I already add psycopy2-binary pack with this.
Related
I am testing my api gateway to call lambda function.
i was successful in the test.
i was then trying to make a connection to postgresql through the same lambda
import json
import psycopg2
db_host = "hostname"
db_port = 5432
db_name ="db name"
db_user ="user"
db_pass ="password"
def connect():
conn = None
try :
conn = psycopg2.connect("dbname={} user={} host={} password={}".format(db_name,db_user,db_host,db_pass))
except :
print("connetion error")
return conn
print("Loading function")
def lambda_handler(event, context):
# paring query from the string
name = event['queryStringParameters']['name']
action = event['queryStringParameters']['action']
print('name = '+name )
print('action = '+action)
# body of the response object
transactionResponse = {}
transactionResponse['name'] = name
transactionResponse['action'] = action
transactionResponse['message'] = 'Lambda called from api_gateway'
# construting Http response
responseObject = {}
responseObject['statusCode'] = 200
responseObject['headers'] {}
responseObject['headers']['Content-Type'] = 'application/json'
responseObject['body'] = json.dumps(transactionResponse)
# return the response object
return responseObject
when i tried to trigger it through the API endpoint i got
Unable to import module 'lambda_function': No module named 'psycopg2'
then i went ahead and build my lambda function by downloading the required package and then uploaded a zip file .
when i try to call try the same to trigger the lambda i am getting
Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'lambda_function'
don't know what lamda_function is .
Could any one suggest me out of this slump ?
or
provide me a way to connect to RDS through lambda from API gateway trigger
This is my build Package
the issue is no longer there.
Get the psycopg2 build library from https://github.com/jkehler/awslambda-psycopg2 was built for python 3.6 and make sure you change the name to psycopg2 while uploading your code to AWS lambda, select Python Runtime environment as 3.6, and it should work.
Can you check the lambda_handler settings and ensure they are correctly set to represent your function:
You should check the lambda handler name from the console. This is likely to be caused because the handler name is referring to lambda_function.foobar but the filename of the Lambda within the zip would be not be named lambda_function.py.
Ensure the name is in the format filename.function_name.
In this example if the file was named lambda_function then the handler value should be lambda_function.lambda_handler.
The directory structure does not currently include the psycopg2 module so this will still not be able to be loaded.
To solve this the following solutions are applicable:
Add the dependency via pip install, then zip up again deploy
Add a Lambda layer with this dependency already installed
As far as I understand, the protractor-cucumber-framework passes through the cucumberOpts object to cucumber, which allows the user to specify cucumber options like strict and tags. I'm trying to use a TeamCity reporter with this framework. According to the instructions for the reporters, (e.g. TeamCity Reporter, to use this reporter you use the --format option to specify the reporter when running cucumber. So my interpretation is that I should specify the format property in the cucumberOpts object in the same way. i.e. cucumber -f TeamCityFormatter::Formatter becomes:
cucumberOpts: {
'format': 'TeamCityFormatter::Formatter'
}
But when I do this, I get the error:
Unhandled rejection Error: ENOENT: no such file or directory, open 'C:\Dev\fork\Billing.Test.Automation.V2\:Formatter':
I thought maybe I just need to specify the name of the module, so I tried:
cucumberOpts: {
'format': 'TeamCityFormatter'
}
Which gave me this error:
Unhandled rejection Error: Cannot find module 'C:\Dev\fork\Billing.Test.Automation.V2\TeamCityFormatter'
So that looks like it is looking for a module, so I tried pointing it to the module in the node_modules folder:
cucumberOpts: {
'format': 'node_modules/teamcity-formatter'
}
And I get this error:
Unhandled rejection TypeError: this.registerHandler is not a function
Is there some special way to use a cucumber reporter via the protractor-cucumber-framework?
Not an answer but an example of how a package can be imported as a plugin
onPrepare:fucntion(){
...
},
// Here the magic happens
plugins: [{
package: 'protractor-multiple-cucumber-html-reporter-plugin',
options: {
automaticallyGenerateReport: true,
removeExistingJsonReportFile: true,
displayDuration: true
}
}],
I read some posts regarding to the error I am seeing now when import pyspark, some suggest to install py4j, and I already did, and yet I am still seeing the error.
I am using a conda environment, here is the steps:
1. create a yml file and include the needed packages (including the py4j)
2. create a env based on the yml
3. create a kernel pointing to the env
4. start the kernel in Jupyter
5. running `import pyspark` throws error: ImportError: No module named py4j.protocol
The issue is resolved with adding environment section in kernel.json and explicitely specify the variables of the following:
"env": {
"HADOOP_CONF_DIR": "/etc/spark2/conf/yarn-conf",
"PYSPARK_PYTHON":"/opt/cloudera/parcels/Anaconda/bin/python",
"SPARK_HOME": "/opt/cloudera/parcels/SPARK2",
"PYTHONPATH": "/opt/cloudera/parcels/SPARK2/lib/spark2/python/lib/py4j-0.10.7-src.zip:/opt/cloudera/parcels/SPARK2/lib/spark2/python/",
"PYTHONSTARTUP": "/opt/cloudera/parcels/SPARK2/lib/spark2/python/pyspark/shell.py",
"PYSPARK_SUBMIT_ARGS": " --master yarn --deploy-mode client pyspark-shell"
}
I've created a vue application scaffolded from the vue cli. Almost everything is reacting as expected with my app except for an issue with import.
The following works fine:
import Vuex from 'vuex';
but, this throws errors:
import { VuetronVue, VuetronVuex } from 'vuetron';
vue.use(VuetronVue);
Linting error:
"export 'VuetronVue' was not found in 'vuetron'
and Console error:
Uncaught TypeError: Cannot read property 'install' of undefined
Changing the code to:
import vuetron from 'vuetron'
vue.use(vuetron.VuetronVue);
resolves the issue...
This original code was taken directly from the Vuetron documentation. Does anyone have a suggestion as to why the ES6 notation would cause an issue?
This seems to be because
vuetron/packages/vuetron-plugins/index.js
only exports the default object:
import VuetronVue from './vuetron-vue';
import VuetronVuex from './vuetron-vuex';
export default {
VuetronVue,
VuetronVuex
};
For named imports as stated in the docs you would need a named export.
i try to get the following code to run:
class common
{
...
# common packages
package
{
["lsb-release", "figlet"]: ensure => installed,
}
# Print some information if someone logs in:
file { "/etc/motd":
#require => [ Package["figlet"], File["/usr/bin/figlet"] ],
require => Package["figlet"],
content => generate('/usr/bin/env', '/usr/bin/figlet','-w', '186', '-p', '-f', 'banner', "$hostname"),
}
....
}
should't this work?
i get the following error:
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to execute generator /usr/bin/env: Execution of '/usr/bin/env /usr/bin/figlet -w 186 -p -f banner hostname' returned 127: /usr/bin/env: /usr/bin/figlet: No such file or directory
at /etc/puppet/modules/common/manifests/init.pp:37 on node puppetmaster.local
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run
first i had no require (row 12) and no package (row 5-8) in the code, to fix the errors i thought to i can simply add the row 12 (require package figlet) but it does not work. so i added the package figlet, but the the error does not go away.
how to add this dependency? shouldn't puppet run through the code and don't skip the run totally?
generate() runs on the server, not the client. (It's a parser function so it has to run on the server)
The class as you've written it will ensure that clients get figlet installed on them, but then tries to run figlet on the puppetmaster. Just install figlet on your puppetmasters and you won't need the package resources.
Also use smslant font, not banner :)