I have a layer where the path of node_modules is nodejs/node14/node_modules.
Using that layer, and I try to import a package in a Lambda function, say 'aws-cloudfront-sign', like this:
import cfsign from 'aws-cloudfront-sign'
I got error message
Cannot find package 'aws-cloudfront-sign' imported from /var/task/signer.js\nDid you mean to import aws-cloudfront-sign/lib/cloudfrontUtil.js?
But if I import the package like this:
import cfsign from '/opt/nodejs/node14/node_modules/aws-cloudfront-sign/lib/cloudfrontUtil.js'
It succeeds.
Do you know why? How could I import the package correctly?
This appears to be a bug. It is occurring with layers and the SDK. There are are a number of similar open issues on Github:
Nodejs Lambda: Cannot find package 'aws-sdk'
Cannot find package when using ES Module and Lambda Layer
ES6 imports don't work in #aws-sdk/client-iotsitewise
As you have worked out, the only workaround at present seems to be the use of absolute paths. E.g.:
import { DynamoDB } from 'aws-sdk;'
fails, whereas
import AWS from '/var/runtime/node_modules/aws-sdk/lib/aws.js';
const { DynamoDB } = AWS;
will work.
I suggest you add your voice to an existing open issue to help ensure it gets attention.
Related
I am trying to set up a locust based framework for ML load test and need to create custom metrics and logs for which the example that I am following is using 'MetricsServiceV2Client' in 'google.cloud.logging_v2' lib.
In the Vertex Workbench on GCP inspite being on v3.0 of the google-cloud-logging lib I am getting an issue of import
from google.cloud import logging_v2
from google.cloud.logging_v2 import MetricsServiceV2Client
error: cannot import name 'MetricsServiceV2Client' from 'google.cloud.logging_v2' (/opt/conda/lib/python3.7/site-packages/google/cloud/logging_v2/__init__.py)
Interestingly when I test the import in Google's cloud console I am able to import without any issue. What could be the issue?
Change it to the following:
from google.cloud.logging_v2.services.metrics_service_v2 import MetricsServiceV2Client
This will work.
To make an http call using python my way was to use requests.
But requests is not installed in lambda context. Using import requests resulted in module is not found error.
The other way is to use the provided lib from botocore.vendored import requests. But this lib is deprecated by AWS.
I want to avoid to package dependencies within my lambda zip file.
What is the smartest solution to make a REST call in python based lambda?
Solution 1)
Since from botocore.vendored import requests is deprecated the recomended way is to install your dependencies.
$ pip install requests
import requests
response = requests.get('https://...')
See also. https://aws.amazon.com/de/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/
But you have to take care for packaging the dependencies within your lambda zip.
Solution 2)
My preferred solution is to use urllib. It's within your lambda execution context.
https://repl.it/#SmaMa/DutifulChocolateApplicationprogrammer
import urllib.request
import json
res = urllib.request.urlopen(urllib.request.Request(
url='http://asdfast.beobit.net/api/',
headers={'Accept': 'application/json'},
method='GET'),
timeout=5)
print(res.status)
print(res.reason)
print(json.loads(res.read()))
Solution 3)
Using http.client, it's also within your lambda execution context.
https://repl.it/#SmaMa/ExoticUnsightlyAstrophysics
import http.client
connection = http.client.HTTPSConnection('fakerestapi.azurewebsites.net')
connection.request('GET', '/api/Books')
response = connection.getresponse()
print(response.read().decode())
My project layout is a pretty simple electron-webpack project structure. In my project I use rxjs, react-redux and react-redux-typescript. At the beginning I used to start my project with electron-forge start and build it using electron-builder. I changed my project layout so I can use electron-webpack start to start my project. When I start my project with electron-forge start everything works correctly but when I start it using electron-webpack dev it gives me this stacktrace.
In both cases (electron-forge start and electron-webpack dev) it is the exact same codebase except the project structure.
My RXJS imports look like so:
import { Observable } from 'rxjs/Observable'
import 'rxjs/add/operators/switchMap'
I also tried using this import style
import Rx from 'rxjs/Rx'
martin is right, you've misspelled import statement, it should be operator, not operators
So, instead of this:
import 'rxjs/add/operators/switchMap'
Do this:
import 'rxjs/add/operator/switchMap
I no longer see the import button on Parse to import a JSON or CSV file. Did they move it somewhere or is it no longer possible to import those file types?
the official reason is this:
"[The import class button] was removed a couple of days ago due to an app that was abusing it and affecting people that had not migrated out yet. Now that the database is running on your own infra, you can simply importing directly to mongo so this shouldn’t be blocking you."
I hope this helps (to answer the question, not to import your class of course).
Cheers,
This question is asked several times, but I can't find the right solution for my problem. I'm trying to import my Player.swift class in my MainScene.swift (I've used Cocos2D - SpriteBuilder to setup the project; Now using Xcode).
This is my folder structure:
I've tried to use import Player; and import Player.swift;, but when I tried I got this error: No such module 'Player.swift'
How do I import it correctly?
Thanks!
By the way, I'm a beginner in Swift, so don't expect that I know all of the terms
You don't need to explicitly import files in Swift as they are globally available through the project. If you want to access the methods or properties of Player class, you can directly make object of Player class in MainScene.Swift file and can access to it.
e.g var objPlayer = Player()
There is no need to import swift classes to use in other swift classes.
They are available to use automatically.
In Swift you can only import module, e.g. any framework like UIKit, MapKit as below. You cannot import swift classes.
import UIKit
import MapKit
Just make sure its selected to use in target in which your are trying to use.
Check below images for more idea.
In this image my HomeViewController.swift is selected to use in AutolayoutDemo module.
In below image I have unchecked AutolayoutDemo module for the class DetailsViewController.swift.
So now onwards when I will try to use the DetailsViewController compiler will give me error as below image in HomeViewController.
When it comes to Swift imports, there are two cases:
1) The type to import is in the module
In this case, no import statement is needed. As long as the type is not private or fileprivate, you can directly access it.
2) The type to import is outside of the module
You can import an entire module using:
import ModuleName
If you only want to import a specific type or function from the module, you can do this using the following format:
import kindOfThing ModuleName.Type
where kindOfThing is class/struct/func/etc...
A much deeper exploration of this can be found on NSHipster here.
Check if the class is added to your iOS target in right Pane or not .