protomaps / PMTiles

Cloud-optimized + compressed single-file tile archives for vector and raster maps
https://protomaps.com/docs/pmtiles/
BSD 3-Clause "New" or "Revised" License
2.12k stars 125 forks source link

lambda function not working? #394

Closed koufopoulosf closed 5 months ago

koufopoulosf commented 7 months ago

Hello,

I have followed all the steps explained here, however the given lambda function, seems to not work as I receive 502 error from cloudfront.

What is interesting, is that if I switch the official lambda function (the one given above) to the one that is generated after following this article, which is using the Serverless Framework (repo can be found here), the map works flawlessly. The generated lambda function can be found here.

Any ideas of what could be the issue?

Thanks in advance for your assistance.

Kind regards, koufopoulosf

bdon commented 7 months ago

Do the requests to the Lambda Function URL (https://AAAA.lambda-url.region-name.on.aws/my_file/0/0/0.mvt) succeed?

koufopoulosf commented 7 months ago

Hello @bdon,

Thank you for your prompt response.

I'm glad to inform you that the issue has been resolved. However, I noticed a potential improvement for the documentation. It would be helpful to mention explicitly that the Lambda function should be organized within a folder and then zipped for proper deployment. Currently, the lambda function provided on the official website (lambda_function.zip) is not structured within a folder, which may cause compatibility issues. Additionally, I observed that the documentation does not specify the handler that points to the Lambda function, which could lead to confusion for users.

If there are any other crucial details missing from the documentation that I should be aware of, please do not hesitate to inform me here or update the documentation accordingly. It might be beneficial to include information on etags and any recent updates that need to be highlighted.

Thank you for your attention to this matter.

Kind regards, koufopoulosf

bdon commented 7 months ago

@koufopoulosf thanks for looking into the resolution. the JS file is zipped up into a folder, however most web browsers by default automatically unzip the file when you download it. If you use cURL or another program to grab https://protomaps.github.io/PMTiles/lambda_function.zip it should have the correct structure, can you confirm that?

I don't know of a way to override that browser behavior.

koufopoulosf commented 7 months ago

@bdon Thank you for your response. To clarify, the issue is not related to browser behavior but rather to the structure of the lambda_function.zip file. The provided lambda_function.zip should not be directly uploaded to S3 as it is. Instead, it should follow the structure: lambda_function.zip > function_folder > index.mjs. This ensures proper functioning. As you observed, the JavaScript file follows the structure: zip file > folder > js code. A structure like the current one: lambda_function.zip > index.mjs, uploaded to S3, simply will not work.

bdon commented 3 months ago

Our current plan is to eliminate the error-prone manual zip file workflow by inlining the Lambda code in a CloudFormation template - see PR at https://github.com/protomaps/PMTiles/pull/435