Lab 77 diagram

100 days in Cloud

Lab 77

Install Python module for Lambda using Cloud9

Services Covered

  • lambdaLambda
  • cloud9Cloud9

Lab description

For a Lambda function to work with the request library it needs to be uploaded as a separate module. To do that a new Cloud9 environment will be started and in it, a pip commands executed in a terminal. Then modules will be packed and upload to Lambda function.

  • Create a Lambda function
  • Create Cloud9 environment
  • Download packages using Terminal and pip
  • Upload libraries in to Lambda

Lab date



  • AWS account

Lab steps

  1. Create a new Lambda function with Python som runtime.
    import json
     import requests
     def lambda_handler(event, context):    
    r = requests.get('')     
    return {        
    'statusCode': 200,        
    'body': json.dumps('success')    }

    If you try and test it will respond with error message because request package is not part of Lambda Python standard library.

  2. Go to Cloud9 and create a new environment. Choose direct access with EC2 instance. This will take some time:
  3. Import the Lambda function to Cloud9. On the left side click on then choose your Lambda and install_request_module then download.
  4. Install request library in Terminal:
  5. Run those commands:
    pip install --target ~/environment/<<LAMBDA NAME>>/ requests
    Then to zip the library run:
    zip -r ../ *
    Download that zip file
  6. Back in Lambda upload that zip package and test your function:


  7. Delete your environment in Cloud9.

Lab files and Github link