0

Here I am I created a flask application and deploying using zappa .

While deployment I am facing no module found exception but same python code it working offline below is my stop.app application

import boto3
from flask import Flask, request,Response, jsonify

app = Flask(__name__)
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
region = 'ap-south-1'
myins = ['i-043ae2fbfc26d423f','i-0df3f5ead69c6428c','i-0bac8502574c0cf1d','i-02e866c4c922f1e27']
@app.route('/', methods=['GET'])
def lambda_handler(event=None, context=None):
    logger.info('Lambda function invoked index()')
    ec2 = boto3.resource('ec2')
    ec2client = boto3.client('ec2',region_name=region)
    ec2client.stop_instances(InstanceIds=myins)
    return 'Instances are stopped!!'
   # if __name__ == '__main__':
   # app.run(debug=True)```




Below is the error 


alling tail for stage dev..
[1568791437587] No module named stop: ImportError
Traceback (most recent call last):
  File "/var/task/handler.py", line 602, in lambda_handler
  return LambdaHandler.lambda_handler(event, context)
  File "/var/task/handler.py", line 245, in lambda_handler
  handler = cls()
  File "/var/task/handler.py", line 139, in __init__
  self.app_module = importlib.import_module(self.settings.APP_MODULE)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
  __import__(name)
ImportError: No module named stop
monica
  • 11
  • 3
  • Possible duplicate of [Lambda error: no module found. Cryptography.hamtaz.bindings.\_constant\_time](https://stackoverflow.com/questions/53583089/lambda-error-no-module-found-cryptography-hamtaz-bindings-constant-time) – Lamanus Sep 18 '19 at 09:40
  • how are you creating the zip – amittn Sep 18 '19 at 10:17

1 Answers1

0
  • Worth checking the way the zip file is created, Also check the uploaded zip if its in the correct format.
  • The lambda_hanlder should be at the base of the root of the zip.
  • User pip install -r requirements.txt -t .
  • Also just a small improvement move the ec2 connection outside of lambda_handler.
  • To start and stop the instance boto3 docs start and stop instance
amittn
  • 2,249
  • 1
  • 12
  • 19
  • Calling update for stage dev.. Warning! Your project and virtualenv have the same name! You may want to re-create your venv with a new name, or explicitly define a 'project_name', as this may cause errors. Downloading and installing dependencies.. - markupsafe==1.1.1: Using locally cached manylinux wheel Packaging project as zip. Uploading aws-dev-1568798783.zip (32.5MiB).. 100%|| 34.1M/34.1M [01:14<00:00, 154KB/s] Updating Lambda function code.. Updating Lambda function configuration.. Uploading aws-dev-template-1568798881.json (1.5KiB).. Deploying API Gateway.. – monica Sep 18 '19 at 10:29
  • @monica sorry are you still facing issues – amittn Sep 19 '19 at 07:52