Sto creando un pacchetto di distribuzione Python AWA Lambda. Sto usando una richiesta di dipendenza esterna. Ho installato la dipendenza esterna utilizzando la documentazione di AWS http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html. Di seguito è riportato il mio codice Python.Errore modulo di importazione Lambda AWS in python
import requests
print('Loading function')
s3 = boto3.client('s3')
def lambda_handler(event, context):
#print("Received event: " + json.dumps(event, indent=2))
# Get the object from the event and show its content type
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key']).decode('utf8')
try:
response = s3.get_object(Bucket=bucket, Key=key)
s3.download_file(bucket,key, '/tmp/data.txt')
lines = [line.rstrip('\n') for line in open('/tmp/data.txt')]
for line in lines:
col=line.split(',')
print(col[5],col[6])
print("CONTENT TYPE: " + response['ContentType'])
return response['ContentType']
except Exception as e:
print(e)
print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket))
raise e
Creato Zip il contenuto della directory del progetto-dir e caricato lambda (Zip il contenuto della directory, non la directory). Quando eseguo la funzione sto ottenendo l'errore sotto indicato.
START RequestId: 9e64e2c7-d0c3-11e5-b34e-75c7fb49d058 Version: $LATEST
**Unable to import module 'lambda_function': No module named lambda_function**
END RequestId: 9e64e2c7-d0c3-11e5-b34e-75c7fb49d058
REPORT RequestId: 9e64e2c7-d0c3-11e5-b34e-75c7fb49d058 Duration: 19.63 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 9 MB
Gentilmente aiutarmi a eseguire il debug dell'errore.
E 'il codice completo? Dall'errore sembra che qualche cosa voglia "importare lambda_function" che non è stato trovato. Forse vuoi 'dalla futura importazione lambda_function'? O semplicemente * pip installa lambda_function * su cmd line. – Berci
@Berci Sto eseguendo questo codice Python nella piattaforma AWS. Non posso usare pip. ovunque nel mio codice sto usando lambda_function. Se copio incollare lo stesso codice nella console AWS funzionerà –
Vedere l'ultimo commento su [questa discussione] (https://gist.github.com/kapilt/770bdf5d2a55b7385a9c) - può essere applicato a te? – kwinkunks