aws-sam-cli: boto3 not available in local Python3.6

Description

boto3 seems to not be available when running lambda functions locally through sam local invoke.

Steps to reproduce

$ sam init # Choose template 1, runtime 9 - python3.6, quick start template 1
$ cd sam-app
$ sam local invoke
Invoking app.lambda_handler (python3.6)
Failed to download a new amazon/aws-sam-cli-emulation-image-python3.6:rapid-1.0.0 image. Invoking with the already downloaded image.
Mounting /private/tmp/sam/sam-app/hello_world as /var/task:ro,delegated inside runtime container
28 Jul 2020 08:40:36,629 [INFO] (/var/runtime/awslambda/bootstrap.py) main started at epoch 1595925636629
28 Jul 2020 08:40:36,639 [INFO] (/var/runtime/awslambda/bootstrap.py) init complete at epoch 1595925636639
START RequestId: fb3c2a3d-7b37-135c-0f0c-7aaee074068a Version: $LATEST
END RequestId: fb3c2a3d-7b37-135c-0f0c-7aaee074068a
REPORT RequestId: fb3c2a3d-7b37-135c-0f0c-7aaee074068a	Init Duration: 157.34 ms	Duration: 2.69 ms	Billed Duration: 100 ms	Memory Size: 128 MB	Max Memory Used: 26 MB

{"statusCode":200,"body":"{\"message\": \"hello world\"}"}
$ # All good so far
$ echo 'import boto3' >> hello_world/app.py
$ sam local invoke
Invoking app.lambda_handler (python3.6)
Failed to download a new amazon/aws-sam-cli-emulation-image-python3.6:rapid-1.0.0 image. Invoking with the already downloaded image.
Mounting /private/tmp/sam/sam-app/hello_world as /var/task:ro,delegated inside runtime container
28 Jul 2020 08:42:07,219 [INFO] (/var/runtime/awslambda/bootstrap.py) main started at epoch 1595925727219
Unable to import module 'app': No module named 'boto3'

START RequestId: fe1c19d9-d036-1c9d-88e6-ee8ebc90ffd7 Version: $LATEST
END RequestId: fe1c19d9-d036-1c9d-88e6-ee8ebc90ffd7
REPORT RequestId: fe1c19d9-d036-1c9d-88e6-ee8ebc90ffd7	Init Duration: 168.50 ms	Duration: 2.02 ms	Billed Duration: 100 ms	Memory Size: 128 MB	Max Memory Used: 26 MB
28 Jul 2020 08:42:07,235 [INFO] (/var/runtime/awslambda/bootstrap.py) init complete at epoch 1595925727235

{"errorMessage":"InvalidErrorShape"}

This used to work with earlier images.

Observed result

Unable to import module 'app': No module named 'boto3'

Expected result

boto3 is supposed to be available in Lambda environments.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Mac OS
  2. sam --version: SAM CLI, version 1.0.0

Add --debug flag to command you are running

$ sam local invoke --debug
Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
local invoke command is called
No Parameters detected in the template
2 resources found in the template
Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/'
Found one Lambda function with name 'HelloWorldFunction'
Invoking app.lambda_handler (python3.6)
No environment variables found for function 'HelloWorldFunction'
Environment variables overrides data is standard format
Loading AWS credentials from session with profile 'None'
Resolving code path. Cwd=/private/tmp/sam/sam-app, CodeUri=hello_world/
Resolved absolute path to code is /private/tmp/sam/sam-app/hello_world
Code /private/tmp/sam/sam-app/hello_world is not a zip/jar file
Failed to download image with name amazon/aws-sam-cli-emulation-image-python3.6:rapid-1.0.0
Failed to download a new amazon/aws-sam-cli-emulation-image-python3.6:rapid-1.0.0 image. Invoking with the already downloaded image.
Mounting /private/tmp/sam/sam-app/hello_world as /var/task:ro,delegated inside runtime container
Starting a timer for 3 seconds for function 'HelloWorldFunction'
28 Jul 2020 08:43:49,216 [INFO] (/var/runtime/awslambda/bootstrap.py) main started at epoch 1595925829217
Unable to import module 'app': No module named 'boto3'

START RequestId: 336d2134-ad65-1030-bef9-c97c7a0a8844 Version: $LATEST
END RequestId: 336d2134-ad65-1030-bef9-c97c7a0a8844
REPORT RequestId: 336d2134-ad65-1030-bef9-c97c7a0a8844	Init Duration: 161.05 ms	Duration: 1.99 ms	Billed Duration: 100 ms	Memory Size: 128 MB	Max Memory Used: 26 MB
28 Jul 2020 08:43:49,229 [INFO] (/var/runtime/awslambda/bootstrap.py) init complete at epoch 1595925829230
Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local invoke', 'duration': 5927, 'exitReason': 'success', 'exitCode': 0, 'requestId': '055268b8-b43a-4822-b371-31abd291f9d9', 'installationId': '6a3ba03d-489c-46e4-8636-3c88565736ff', 'sessionId': '42e27585-9444-4a23-8fe6-8ac3774be51e', 'executionEnvironment': 'CLI', 'pyversion': '3.7.8', 'samcliVersion': '1.0.0'}}]}
HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

{"errorMessage":"InvalidErrorShape"}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 9
  • Comments: 26 (7 by maintainers)

Most upvoted comments

+1, not clear how to downgrade to 0.53.0 using Homebrew, reinstalled using pip instead.

Been meaning to post this, but been a bit swamped. It works fine on sam 0.53.0, so that’s where I’m staying for the time being.