AWS Lambda package-deployed functions require() of a relative path, not found - amazon-s3

I have a zip file containing the following structure (this is the root of the archive, not nested in a top-level folder, which I understand is a common cause of errors for aws-s3-lambda deployments):
- support/
- shared.js
- one.js
- two.js
and then in one.js and two.js:
var shared = require("./support/shared");
// ...
When I run this code locally, it works. I use the aws-sdk to upload the zip file to AWS-S3 and then use aws.lambda.createFunction() to create a function with that name and handler and everything. The created function DOES show up in my Lambda dashboard, but when I test it, I get "Cannot find module './support/shared'". I have also tried var shared = require("./support/shared.js"); and that gives "Cannot find module './support/shared.js'".
This is for runtime node6.10. The filename cases are correct for case-sensitive lambda.
Shouldn't this work?? What's the gotcha?
Is there a way to verify the file structure that Lambda is working in to show that the additional ./support/shared.js file actually made it to the working directory or whatever it uses?

The gotcha is that the zip file created on a windows machine has the wrong chmod permissions set in it for when AWS unpacks it. The files are there, but inaccessible but node just gives a generic warning about not found instead of that the folder access is denied.

Related

NestJS Multer set dest to an url

Hello!
So, when i upload a file with nestjs and multer, i want to set the dest in the module to an url, but if i do that, then it gives me an error:
EINVAL: invalid argument, mkdir 'C:\Users\almak\Desktop\Chatenium2\chatenium-server\http:\localhost'
Can you help me why? Thanks, and also is there any way to prevent nestjs from renaming and removing the file extension from the file (test.png => 03ebe1f47494378fee61196c0524afaf )
Heres the code:
Module:
MulterModule.register({
dest: process.env.CDN_URL,
}),
Controller:
#Post("uploadImg")
#UseInterceptors(FileInterceptor("file"))
async uploadedFile(#UploadedFile() file) {
return file;
}
dest by default is a local directory for the server to access via the fs module. If you need to upload the file to another server from your server, you should use a different storage type.
As for the renaming of the file, that's also multer's default, you can pass options to the FileInterceptor according to multer's documentation to change how the file gets handled.

How to work with mulitple annotation folder in latest version of darkaonline/l5-swagger?

It was working perfectly with multiple annotation folders in laravel 8.0, forgot the minor version of l5-swagger. Later when I do composer update and darkoline get updated to ^8.3 version. Now, its trying to make documentation(#SchemaRef) out of each file stored inside the folder. I do have following configuration
/*
* Absolute paths to directory containing the swagger annotations are stored.
*/
annotations' => [
base_path('app'),
base_path('Modules'),
]
In my case I do have following error
ErrorException
Skipping unknown \CreateRolesTable
Here CretaetRolesTable is a migration file inside Modules folder, no swagger related annotation exists in CreateRolesTable file and neither this name is being used as #ref.
You should use the anonymous function in CreateRolesTable file.
return new class extends Migration
For more information check the official documentation.(see more)

IntelliJ + AWS Toolkit + Serverless App: "Must be able to locate the handler in the project in order to deploy to Lambda"

I have created a new Serverless project in IntelliJ using a HelloWorld style template app.
This app I managed to build, deploy and run remotely in my AWS account. I even managed to integrate it with API gateway to make it accessible through the internet.
As the project is setup, it has 1 Lambda function called HelloWorldFunction. Its handler is called "helloworld.App::handleRequest" and I can see the configuration for this in the template.yaml file.
Now I want to create another Lambda function in the same application project. So, in IntelliJ, I follow these steps:
AWS Explorer > Lambda
Right-click on Lambda
Click "Create new AWS Lambda ..."
enter a function name (e.g. MyNewLambdaFunction)
enter the runtime (Java 8) and the S3 bucket and the IAM role (all is fine)
then I need to enter the name of the "Handler", and this is where my problem starts
I have tried different names here, such as "MyNewHandler", or "helloworld.App::handleRequest" (clearly this wouldn't work because it's already in use by the HelloWorldFunction), "helloworld.App2::handleRequest", .... and so on.
Each time I try another name or way to define the Handler, I get this error message:
Must be able to locate the handler in the project in order to deploy
to Lambda
Question:
Do I need to first configure the new Lambda function in the template.yaml file or what do I need to call the Handler so it will work?
I am sure this is just a noob-error but I have been Googling this and haven't found anyone who has run into the same problem. I also read up on AWS on handlers but it only describes it at a conceptual level and not in practice where there are multiple Lambdas.
thanks for any help!
Andy
My understanding is that you would need to add app2 class to the same package first:
click on the package name → new → Java Class → type app2
Navigate to the implementation of the App2 class and click on the lambda icon in the gutter. You will notice that "Create New AWS Lambda" is added to the dropdown:
When you select it, you will see that "Handler:" field has already been prepopulated correctly:
my understanding is that each handler must be placed in a separate class and the name of the handler handleRequest is standard and provided by the framework
I've had the same issues using pyCharm for Python.
I was able to solve it by using <file name without extension>.<function name> so my file is app.py and the function is lambda_handler so my handler was app.hello_world
It should be noted this is the same as what you see in the "Handler" field when using the AWS web management page.
Thius is how it looks in pycharm:
I got the same issue but solved in a different way;
Quit WebStorm
Delete ".aws-sam" and ".idea" folders
Open the project again.
"Update function code" run without "Must be able to locate the handler in the project in order to deploy to Lambda"

Safari Push Notifications - Verifying hashes in manifest.json failed even though correct

I have created a push package with the appropriate files as per the Apple spec for APNS. This manifest file represents all of the files that are present:
{
"icon.iconset/icon_128x128.png": "78609fcff69688f969a38f957ac2f10fc79d6732",
"icon.iconset/icon_128x128#2x.png": "78609fcff69688f969a38f957ac2f10fc79d6732",
"icon.iconset/icon_16x16.png": "d348589e2cf37d8f23940f8545afe75a2e98b4ac",
"icon.iconset/icon_16x16#2x.png": "d348589e2cf37d8f23940f8545afe75a2e98b4ac",
"icon.iconset/icon_32x32.png": "e4418a1c5f2ecfbb702961515aaa65d5449b1c53",
"icon.iconset/icon_32x32#2x.png": "e4418a1c5f2ecfbb702961515aaa65d5449b1c53",
"website.json": "45be9c4a6f1bf96e27a9eecab219304b35c5ac24"
}
I have manually checked the sha1 values on the CLI and they are all correct, along with the file locations. And yet I still get this error back from Safari each time I try to get permission:
{ '{"logs":': { '"Verifying hashes in manifest.json failed"]': '' } }
Which is not valid JSON either. Any ideas why this would be failing?
I recently implemented push notifications through pushwoosh. They automatically created the package for me and I checked how they done it. The only difference between mine manifest file and your is a back slash before the normal slash. Maybe it could do the difference for you. Copy and paste this code in your manifest (I have already added your SHA1 values):
{"icon.iconset\/icon_16x16.png":"d348589e2cf37d8f23940f8545afe75a2e98b4ac","icon.iconset\/icon_16x16#2x.png":"d348589e2cf37d8f23940f8545afe75a2e98b4ac","icon.iconset\/icon_32x32.png":"e4418a1c5f2ecfbb702961515aaa65d5449b1c53","icon.iconset\/icon_32x32#2x.png":"e4418a1c5f2ecfbb702961515aaa65d5449b1c53","icon.iconset\/icon_128x128.png":"78609fcff69688f969a38f957ac2f10fc79d6732","icon.iconset\/icon_128x128#2x.png":"78609fcff69688f969a38f957ac2f10fc79d6732","website.json":"45be9c4a6f1bf96e27a9eecab219304b35c5ac24"}
I created a small ruby script for generating these manifests based on the code in https://github.com/SymmetricInfinity/push_package/blob/master/lib/push_package.rb.
Copy the script into a directory containing an icon.iconset directory and your website.json. Then you can run ruby gen_manifest.rb inside that directory and the script will write the manifest.json. At the very least it may be a sanity check to see that everything is correct. The script is here: https://gist.github.com/adamvduke/7934457
If you don't have any ruby experience, comment back and I can walk you through it.

F4 IDE gives "Invalid Uri scheme for local file" when running Fantom app

I started a very simple project using Xored's F4 IDE for Fantom. The first few times I ran it there was no error, but I started adding dependencies (fanbatis) and at some point the error below starting showing up every time I run a test or a dummy Hello World app.
[23:44:18 22-Nov-13] [err] [pathenv] Cannot parse path: C:\dev\f4workspace\auth\bin\fan
sys::ArgErr: Invalid Uri scheme for local file: c:\dev\f4workspace\auth\bin\fan/
fan.sys.LocalFile.uriToFile (LocalFile.java:64)
fan.sys.File.make (File.java:26)
util::PathEnv.parsePath (PathEnv.fan:47)
fan.sys.List.each (List.java:555)
util::PathEnv.parsePath (PathEnv.fan:43)
util::PathEnv.make$ (PathEnv.fan:22)
util::PathEnv.make (PathEnv.fan:20)
java.lang.reflect.Method.invoke (Unknown)
fan.sys.Method.invoke (Method.java:559)
fan.sys.Method$MethodFunc.callList (Method.java:198)
fan.sys.Type.make (Type.java:246)
fan.sys.ClassType.make (ClassType.java:110)
fan.sys.Type.make (Type.java:236)
fan.sys.Sys.initEnv (Sys.java:447)
fan.sys.Sys. (Sys.java:224)
fanx.tools.Fan.execute (Fan.java:28)
fanx.tools.Fan.run (Fan.java:298)
fanx.tools.Fan.main (Fan.java:336)
Hello, World!
It is more a nuisance at the moment because the tests and the dummy app still run. I created another project, copying all the source code adding class by class and testing after each change and the error never occurred. Any ideas please?
That's an interesting issue!
tl/dr: you have an empty project 'auth' in your workspace, either create some dummy class inside it or go to Run -> Run configurations, find your launch config and uncheck project without sources on 'Projects' tab.
In order to keep your Fantom installation clean from projects in a workspace, F4 puts built pods into project/bin/fan/lib/fan. When F4 launches projects from workspace, it uses PathEnv and builds FAN_ENV_PATH by joining paths to Fantom installation and bin/ folders in projects in workspace.
When Fantom runtime analyzes FAN_ENV_PATH, at first it interprets a path as native OS path, but if dir does not exist, it attempts to interpret it as file URI, here's relevant part of PathEnv source:
path.split(File.pathSep[0]).each |item|
{
if (item.isEmpty) return
dir := File.os(item).normalize
if (!dir.exists) dir = File(item.toUri.plusSlash, false).normalize
if (!dir.exists) { log.warn("Dir not found: $dir"); return }
The problem code is item.toUri – On Mac OS X and Linux this is parsed as an URI without scheme with path only, so if directory does not exist, this code just prints a warning in a console.
But on Windows, because of disk name in path, disk name is interpreted as scheme:
fansh> "C:\\Users".toUri { echo(path); echo(scheme) }
[\Users]
c
fansh> "/Users".toUri { echo(path); echo(scheme) }
[Users]
null
And then File constructor fails, because expects either 'file' scheme, or null scheme:
public static java.io.File uriToFile(Uri uri)
{
if (uri.scheme() != null && !uri.scheme().equals("file"))
throw ArgErr.make("Invalid Uri scheme for local file: " + uri);
return new java.io.File(uriToPath(uri));
}
I've created an issue here, so that F4 would automatically skip empty projects when building FAN_ENV_PATH – https://github.com/xored/f4/issues/25.
I thought the problem had something to do with the forward slash at the end of path as shown in this line of the error message
Invalid Uri scheme for local file: c:\dev\f4workspace\auth\bin\fan/
However, I found that such path didn't exist. I manually created both the bin and the fan folders and the error disappeared. To be honest I don't really know why F4 needs and checks for that folder because so far it hasn't written any file in it.