Can't locate URI/Escape.pm in #INC on AWS lambda - perl

I have an AWS Lamba function in python that generates a url using a shell script.
The input parameters to the shell script is provided by the python code.
The shell script uses perl to URL encode the required URL.
This script runs fine when I run in locally;however on AWS lamba looks like the perl MURI is not installed. Would appreciate if there is alternative way to do this or any other suggestions to go about it.I am doing URL encode by the following commands. The error I see in lambda logs is:
Can't locate URI/Escape.pm in #INC (#INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.
Code in the script is
cred=$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$PARM1/$DATE/$PUBLIC_REGION/$SERVICE_NAME/request")
FULLDT=$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$FULLDT")
SESSION_TOKEN=$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$SESSION_TOKEN")

however on AWS lamba looks like the perl MURI is not installed
You're almost right. the -M is a command-line option telling Perl to load a module. The complete module name is "URI::Escape".
And, yes, that module isn't part of a standard Perl installation, so you'll need to install it separately as part of whatever process you use to set up the environment that your lambda runs in. The simplest approach is probably to run:
cpan URI::Escape
But I'm not sure how that would translate to the lambda environment.

Related

Perl CPAN Can't locate CPAN/Author.pm... when trying to install nipe

I'm trying to install "nipe" on my Windows Machine but i get this error code all the time. I have installed Strawberry Perl.
This is the error code:
Can't locate CPAN/Author.pm in #INC (you may need to install the CPAN::Author module) (#INC contains: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl) at /usr/share/perl5/core_perl/CPAN.pm line 19.
BEGIN failed--compilation aborted at /usr/share/perl5/core_perl/CPAN.pm line 19.
Compilation failed in require at /usr/share/perl5/core_perl/App/Cpan.pm line 290.
BEGIN failed--compilation aborted at /usr/share/perl5/core_perl/App/Cpan.pm line 290.
Compilation failed in require at /c/Strawberry/perl/bin/cpan line 7.
BEGIN failed--compilation aborted at /c/Strawberry/perl/bin/cpan line 7.
While you may have Strawberry Perl installed, that's not the perl you are using. C:\Strawberry\perl\bin\cpan uses the first perl in your PATH, which isn't your installation of Strawberry Perl. It appears that you are using some unix emulation (Cygwin? MSYS?) and using the perl from that emulation.
To use your Strawberry Perl build of perl, you could adjust your PATH so that SP comes before whatever perl you ended up using, or you could use
C:\Strawberry\perl\bin\perl C:\Strawberry\perl\bin\cpan Try::Tiny Config::Simple JSON
or
C:\Strawberry\perl\bin\perl -MCPAN -e"install #ARGV" Try::Tiny Config::Simple JSON
in lieu of
cpan Try::Tiny Config::Simple JSON
Similarly, if you don't adjust your path, you'll need to use
C:\Strawberry\perl\bin\perl nipe.pl ...
in lieu of
perl nipe.pl ...
If your are using windows and a bash then try to it with cmd or powershell after you applied the changes from #ikegami. Took me some time to figure out, that it had no effect to change the paths for this terminal, as it still took the paths from /usr//perl5/
I tried to do all of the other answers, but it didn't work. Instead it appeared that it doesn't work because I tried to run it from unix shell script (sh in powershell or git bash). After moving it from .sh to .ps1 and running non-unix way it works perfectly.

Can't locate XML/LibXML.pm in #INC

I am trying to run script which uses XML/LibXML package.
But, XML/LibXML package is already installed. I ran following command:
perl -MXML::LibXML -e 1. it did not give any output, that means this package is installed.
when i ran my script. Following error occured.
Can't locate XML/LibXML.pm in #INC (#INC contains:
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl
/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl
/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8
.). BEGIN failed--compilation aborted.
One more point to note is there is no directory "5.8.8" under /usr/lib64/perl5/site_perl/
Please suggest to overcome this issue.
There are three possibilities:
You have two installs of perl and you script is using the "wrong" one.
Either install XML::LibXML using the perl used by the script, or replace the script's shebang (#!) line with the output of the following:
perl -MXML::LibXML -le'print "#!".$^X'
Differences in the environment.
If XML::LibXML was installed in a nonstandard directory, it could be that PERL5LIB was used to communicate this to perl when you executed your test, but not when you run the script.
A permission issue.
This isn't very likely.
If the script is run as the same user as your test, it's not a permission issue.
If it is a permission issue, make sure the library directory is accessible to the user executing the script.

Cannot use already installed Perl Module on cPanel

I have already successfully installed the Perl module Crypt::CBC on cPanel.
But when adding the line "use Crypt::CBC;" I am getting the error:
Can't locate Crypt/CBC.pm in #INC (#INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at sagepay.pl line 128.
BEGIN failed--compilation aborted at sagepay.pl line 128.
Did I miss something? Quite new to Perl modules installation.
check the value of #INC by running this using your web server:
perl -e 'print "Content-type: text/plain\r\n\r\n" . join(":",#INC);'
#INC is where perl looks for modules. Perhaps they got installed in the wrong location.
You can add new locations with perl's -I option (see "man perlrun" for details)
I suspect that you may have added the module to cPanel instead of to the system Perl, for which you need to use WHM. Take a look at these instructions and follow the directions headed Install modules to the system Perl binary
Thanks everyone! Just a wrong path, I used this and it now works:
use lib '/data01/c1501978/perl/usr/lib/perl5';

Can't locate XML/XPath.pm in #INC

I have a .pl script in which starts by:
#!/usr/bin/perl
use XML::XPath;
use Getopt::Long;
I can't seem to run that via perl myScript.pl, having this error:
(#INC contains: /usr/share/ /usr/local/lib64/perl5 /usr/local/share/perl5/usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at most_generic_wrapper.pl line 3.
BEGIN failed--compilation aborted at myScript.pl line 3.
1- I tried to locate the XPath.pm file and export that as:
export PERL5LIB=/usr/share/perl5/XML/Twig
and
export PERL5LIB=/usr/share/perl5/XML
2- Installed perl -MCPAN -e 'install XML::Parser'
3- Used -I to explicitly define the path as:
perl -I perl -MCPAN -e 'install XML::Parser' myScript.pl
4- changing the line 3 to use XML::Twig::XPath; led to:
cannot use XML::Twig::XPath: neither XML::XPathEngine 0.09+ nor XML::XPath are available at /usr/share/perl5/XML/Twig/XPath.pm line 11.
BEGIN failed--compilation aborted at /usr/share/perl5/XML/Twig/XPath.pm line 13.`
But none of them solved the issue and I keep receiving the same error at line.3.
P.S: Running on CentOS 6.2 with the kernel 2.6.32-358 and perl --version=v5.10.1 (*) built for x86_64-linux-thread-multi
Any helps would be appreciated,
Your title says XML::XPath can't be found, but your question indicates you tried to install XML::Parser. Did you try to install XML::XPath?
From man perlrun: "If PERL5LIB is not defined, PERLLIB". You seem to have tried setting PERLIB5 (notice the spelling difference: the var is PERL5LIB (or PERLLIB), not PERLIB5).
From man perlrun: "PERL5LIB -- A list of directories in which to look for Perl library files before looking in the standard library and the current directory." You seem to have tried setting it to the full path to a .pm file, rather than a directory.
The file you assigned would be XML::Twig::XPath, not XML::XPath; those are two different Perl modules.
Edit: After looking at your revised question:
I'm not sure if your script requires XML::Twig::XPath or XML::XPath, or if either one can provide the API you need. However, XML::Twig::XPath seems to depend on XML::XPath so you will need XML::XPath no matter what, and it looks like XML::XPath is not installed on your system. I think that's probably the main problem. Please try to install XML::XPath using CPAN.
The value of the PERL5LIB variable (or the argument to the -I option) should be the directory that sits at the base of the package-qualified module file. For example, if XML::XPath is located at ~/perl_custom_modules/XML/XPath.pm, then you need to set PERL5LIB (or the -I argument) to ~/perl_custom_modules. The XML directory is part of the package qualification of the module, so does not need to be included in the include path.

Perl can't find module when run from cron.daily

I have perl programs that use Net::Finger and have run successfully from cron.daily in Fedora 11.
I just upgraded a server to Fedora 18 and these same perl programs no longer run from cron but run fine from command line when logged in as root.
The error is:
Can't locate Net/Finger.pm in #INC (#INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .)
The path to the module is /root/perl5/lib/perl5/Net/Finger.pm but I can't figure out how to add the path without causing more errors.
Thanks in advance.
See perlfaq8.
Here are three ways to add arbitrary directories to Perl's module search path.
Set the PERL5LIB environment variable
15 15 * * 1-5 PERL5LIB=/root/perl5/lib/perl5 /usr/local/bin/perl my_script.pl
Use the -I command line switch
15 15 * * 1-5 /usr/local/bin/perl -I/root/perl5/lib/perl5 my_script.pl
Use the lib pragma inside your perl script
#! /usr/local/bin/perl
# my_script.pl: the script that does my thing
use lib '/root/perl5/lib/perl5';
use Net::Finger;
...
Also note that the environment of a cron job is much sparser than the environment of your command line, and in particular the cron environment's $PATH variable might not be what you expect. If you're not specifying the full path to the Perl executable, verify what $PATH the cron environment is using and make sure you are running the right version of perl.
What happens if you add this to the top of the script?
#!/usr/bin/perl
use lib "/root/perl5/lib/perl5/Net";
Was this previously set in the .profile?
This is from a ubuntu thread, but may be related:
https://askubuntu.com/questions/23009/reasons-why-crontab-does-not-work
*Cron passes a minimal set of environment variables to your jobs. To see the difference, add a dummy job like this:
* * * * * env > /tmp/env.output*
I don't have a linux box handy at the moment, but I would try to see what's different in the #INC by running the following logged in as root and trying to set up a job to see what the crontab has. The env output above may indicate a different shell is being used by crontab, than what you may have set when logging in as root.
log in as root and run:
perl -le 'print for #INC'
set up a cron job to see the differences. I'm not sure if this syntax will work, but you could put the command in a simple pl script.
* * * * * perl -le 'print for #INC' > /tmp/inc.output
do the same for env