import python functions into serversless - serverless

I h got an issue with the following serverless config.
this is my handler and the files/folders structure.
the issue is that after uploading my project to AWS when I test my lambda I got an error as follows:
lambda execution fails: "errorMessage": "Unable to import module 'app_monitor': No module named 'monitoring'"
{
"errorMessage": "Unable to import module 'src/app_monitor': No module named 'monitoring'",
"errorType": "Runtime.ImportModuleError",
"requestId": "bca3f67d-815f-452b-a2a6-c713ad2c6baa",
"stackTrace": []
}
have you got any clue how can I add this into serverless config.?

First, a quick tip on troubleshooting: When I ran into such issues it was helpful to go to the AWS console, look at the lambda function, and see what the uploaded file structure looks like on that end. Is the monitoring folder there?
Moreover, in order to specify how a specific function is packaged, you have to explicitly state that you want it to be individually packaged and not follow the general rules of the project as a whole.
You should try to add:
app_monitoring:
package:
individually: true
patterns:
- 'src/**'
More documentation on packaging configuration here
You may also have better luck with explicitly stating the patterns you need, I know I've had issues with globs in the past. So for example you can try:
patterns:
- 'src/app_monitoring.py'
- 'src/monitoring/get_lb.py'

Related

How do I access parsing of .nimble files from the nimble package?

Nim as a language provides .nimble files to describe its packages (example of a .nimble file). I know that the file is parsed by the nimble package and CLI-tool, as they need the information inside the .nimble file for their tasks.
I want basically all the information in there, dependencies, author, license, description, version, all of it. So in order to not do the same work twice and potentially run into issues should the format change, I would like to use the nimble package itself to parse the .nimble file for me.
I know the correct proc for it, which is getPkgInfoFromFile, but I can't seem to access it with import nimble/nimblepkg/packageparser.
Whenever I use that line I receive an error that there is no such file.
What am I doing wrong?
Further: getPkgInfoFromFile requires an Options instance that it generates when parsing a CLI command. I don't have a CLI command, so I'm not generating such an instance, can I use the proc somehow without one?
Thanks to ringabout I came to the correct solution, but first to the question.
Question 1: How do I access the proc in the first place?
You can access nimble like a package, but the import is not import nimble/nimblepkg/packageparser it is directly import nimblepkg/packageparser.
This requires you to have both nimble' installed as a library as well as the compiler` installed as a library.
So you'll have to install those first:
nimble install nimble
nimble install nim # Originally this was called "compiler", but was renamed to "nim"
Ignore any warnings if they pop up.
Now you can compile the following dummy-example:
#dummy.nim
import nimblepkg/packageparser
echo "Pointer to packageparser proc: ", packageparser.getPkgInfoFromFile.repr
with: nimble -d:ssl --mm:refc -r build (-d:ssl is required for nimble's HTTP-client and --mm:refc is required as nimble appears to not work with orc)
Question 2: Can I run the getPkgInfoFromFile without an Options instance?
Yes-ish. You still need one, but it doesn't have to be a "real" one, you can just instantiate one yourself on the fly.
import nimblepkg/[options, packageinfotypes, packageparser]
proc generateDummyOptions(): Options =
result = initOptions()
result.setNimBin()
result.setNimbleDir()
proc parseNimbleFile*(nimblePath: string): PackageInfo =
let options = generateDummyOptions()
result = getPkgInfoFromFile(nimblePath.NimbleFile, options)

Using Mosek with Drake on Deepnote

ValueError: "MosekSolver cannot Solve because MosekSolver::available() is false, i.e., MosekSolver has not been compiled as part of this binary. Refer to the MosekSolver class overview documentation for how to compile it."
Hi, I got the above error when trying to use the Mosek solver in Drake. It is not clear to me how to enable Mosek in Deepnote with Drake. Do I need to include something in the Dockerfile or the init file? Any tips would be appreciated.
Links I looked at:
https://drake.mit.edu/pydrake/pydrake.solvers.mosek.html
https://drake.mit.edu/bazel.html#mosek
Mosek+Drake does work on Deepnote. The workflow is like this:
Obtain a Mosek license file (from the Mosek website), and upload it to Deepnote.
Set an environment variable to tell Drake where to find the license file. For instance, you can add the following at the top of your notebook:
import os
os["MOSEKLM_LICENSE_FILE"] = "mosek.lic"
Now MosekSolver.available() should be True, and Mosek will even be chosen as the default preferred solver for if you simply call Solve(prog).
Note: Please be very careful not to share the Deepnote notebook with your mosek.lic uploaded.

Why is this route test failing?

I've been following along with the testdriven.io tutorial for setting up a FastAPI with Docker. The first test I've written using PyTest errored out with the following message:
TypeError: Settings(environment='dev', testing=True, database_url=AnyUrl('postgres://postgres:postgres#web-db:5432/web_test', scheme='postgres', user='*****', password='*****', host='web-db',host_type='int_domain', port='5432', path='/web_test')) is not a callable object.
Looking at the picture, you'll notice that the Settings object has a strange form; in particular, its database_url parameter seems to be wrapping a bunch of other parameters like password, port, and path. However, as shown below my Settings class takes a different form.
From config.py:
# ...imports
class Settings(BaseSettings):
environment: str = os.getenv("ENVIRONMENT", "dev")
testing: bool = os.getenv("TESTING", 0)
database_url: AnyUrl = os.environ.get("DATABASE_URL")
#lru_cache()
def get_settings() -> BaseSettings:
log.info("Loading config settings from the environment...")
return Settings()
Then, in the conftest.py module, I've overridden the settings above with the following:
import os
import pytest
from fastapi.testclient import TestClient
from app.main import create_application
from app.config import get_settings, Settings
def get_settings_override():
return Settings(testing=1, database_url=os.environ.get("DATABASE_TEST_URL"))
#pytest.fixture(scope="module")
def test_app():
app = create_application()
app.dependency_overrides[get_settings] = get_settings_override()
with TestClient(app) as test_client:
yield test_client
As for the offending test itself, that looks like the following:
def test_ping(test_app):
response = test_app.get("/ping")
assert response.status_code == 200
assert response.json() == {"environment": "dev", "ping": "pong", "testing": True}
The container is successfully running on my localhost without issue; this leads me to believe that the issue is wholly related to how I've set up the test and its associated config. However, the structure of the error and how database_url is wrapping up all these key-value pairs from docker-compose.yml gives me the sense that my syntax error could be elsewhere.
At this juncture, I'm not sure if the issue has something to do with how I set up test_ping.py, my construction of the settings_override, with the format of my docker-compose.yml file, or something else altogether.
So far, I've tried to fix this issue by reading up on the use of dependency overrides in FastApi, noodling with my indentation in the docker-compose, changing the TestClient from one provided by starlette to that provided by FastAPI, and manually entering testing mode.
Something I noticed when attempting to manually go into testing mode was that the container doesn't want to follow suit. I've tried setting testing to 1 in docker-compose.yml, and testing: bool = True in config.Settings.
I'm new to all of the relevant tech here and bamboozled. What is causing this discrepancy with my test? Any and all insight would be greatly appreciated. If you need to see any other files, or are interested in the package structure, just let me know. Many thanks.
Any dependency override through app.dependency_overrides should provide the function being overridden as the key and the function that should be used instead. In your case you're assigning the correct override, but you're assigning the result of the function as the override, and not the override itself:
app.dependency_overrides[get_settings] = get_settings_override()
.. this should be:
app.dependency_overrides[get_settings] = get_settings_override
The error message shows that FastAPI tried to call your dictionary as a function, something that hints to it expecting a function instead.

Beam/Dataflow: No session file found: /var/opt/google/dataflow/pickled_main_session

When using Apache Beam (GCP Dataflow) I see the following warning in worker logs:
No session file found: /var/opt/google/dataflow/pickled_main_session.
Functions defined in __main__ (interactive session) may fail.
My Dataflow job seems to be fine regardless, but I'm wondering what this warning is all about.
I have seen the following in some sample code (which I am NOT currently doing):
pipeline_options.view_as(SetupOptions).save_main_session = True
where pipeline_options is the main way of specifying options for the Beam/Dataflow pipeline, as in the following later in the code:
with beam.Pipeline(options=pipeline_options) as p:
# actual pipeline code here
I am curious if the two are related. Does the presence of the warning mean I should always be saving the main session? Are these two things related? Unrelated?
You should be able to safely ignore this warning. No need to set save_main_session if it's not required for your pipeline.

F#: unable to use Suave.Types for build script

Trying to use Thomas Petriek's build script: https://github.com/tpetricek/suave-xplat-gettingstarted/blob/master/build.fsx
Getting error that the namespace Types is not defined in open Suave.Types.
Is this some namespace that has since been deprecated?
I am not sure if that is an old version of the build script, but I am using the same build script myself, I had to make a couple of changes namely, remove the logging, use
open Suave.Http
instead of
open Suave.Types
and use these bindings
bindings = [ HttpBinding.create Protocol.HTTP Net.IPAddress.Loopback 8083us ]

Resources