Causes and solutions when python sam build fails in a newly created Cloud9 environment

The beginning of the matter

The other day (one day in September 2020), I tried to output sam (Serverless Application Model) hello world template (runtime is python3.8) in the newly created AWS Cloud9 development environment (platform = AmazonLinux) and try build and deploy. When I tried to build with the "sam build --use-container" command, I encountered the following error. I got an error (Runtime Error: Container does not exist) in the environment I just created, so I got "What ??".

(↓ is for reference, until the hello_world template is output)

ec2-user:~/environment $ sam init --runtime python3.8 -n sam-py38

        SAM CLI now collects telemetry to better understand customer needs.

        You can OPT OUT and disable telemetry collection by setting the
        environment variable SAM_CLI_TELEMETRY=0 in your shell.
        Thanks for your help!

        Learn More: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-telemetry.html

Which template source would you like to use?
        1 - AWS Quick Start Templates
        2 - Custom Template Location
Choice: 1

Allow SAM CLI to download AWS-provided quick start templates from Github [Y/n]: Y

AWS quick start application templates:
        1 - Hello World Example
        2 - EventBridge Hello World
        3 - EventBridge App from scratch (100+ Event Schemas)
        4 - Step Functions Sample App (Stock Trader)
        5 - Elastic File System Sample App
Template selection: 1

-----------------------
Generating application:
-----------------------
Name: sam-py38
Runtime: python3.8
Dependency Manager: pip
Application Template: hello-world
Output Directory: .

Next steps can be found in the README file at ./sam-py38/README.md
ec2-user:~/environment $ cd sam-py38/

(The place where the sam build command of hello_world output by ↓ becomes RuntimeError)

ec2-user:~/environment/sam-py38 $ sam build --use-container
Starting Build inside a container
Building resource 'HelloWorldFunction'

Fetching lambci/lambda:build-python3.8 Docker container image.....................................................................................................................................................................................................................................................
Mounting /home/ec2-user/environment/sam-py38/hello_world as /tmp/samcli/source:ro,delegated inside runtime container
Traceback (most recent call last):
  File "/usr/local/bin/sam", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib64/python3.6/site-packages/click/core.py", line 764, in __call__
~ (Omitted) ~
  File "/usr/local/lib/python3.6/site-packages/samcli/local/docker/container.py", line 197, in wait_for_logs
    raise RuntimeError("Container does not exist. Cannot get logs for this container")
RuntimeError: Container does not exist. Cannot get logs for this container

Cause and solution

I did not know the cause intuitively from the error message, so when I contacted AWS support,

Due to insufficient capacity of the EBS volume associated with the EC2 instance in the Cloud9 environment

I received the answer.

I solved it by expanding the capacity of the EBS volume to 20G by referring to the following document.

Resize an Amazon EBS volume used by an environment https://docs.aws.amazon.com/cloud9/latest/user-guide/move-environment.html#move-environment-resize

The size expansion by this method is also introduced in the article below, and it can be expanded very easily. Increase the disk size of AWS Cloud9 https://qiita.com/Keisuke69/items/af87eb8629ad4249bd22

The initial volume size will quickly run out, especially if you're doing docker-related work on Cloud9, so remember how to easily expand the volume as needed using resize.sh. I think it's convenient.

It's easy, but that's it. I hope that fewer people will have trouble with the same problem.

Recommended Posts

Causes and solutions when python sam build fails in a newly created Cloud9 environment
Build a Python + OpenCV environment on Cloud9
(One of the solutions) when pyenv install on macOS causes BUILD FAILED and Python installation fails.
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a Python environment offline
Try running python in a Django environment created with pipenv
Build a Python development environment in Eclipse (add HTML editor)
Build a Python environment and transfer data to the server
I created a class in Python and tried duck typing
Problems and solutions when asked for MySQL db in Python 3
Build and test a CI environment for multiple versions of Python
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
Build a Python environment on your Mac with Anaconda and PyCharm
Build a detonation velocity website with Cloud Run and Python (Flask)
Build and try an OpenCV & Python environment in minutes using Docker
Build a python3 environment on CentOS7
When writing a program in Python
Build a development environment using Jupyter and Flask with Python in Docker (supports both VS Code / code-server)
[AWS] Problem avoidance memo when installing awscli and boto3 in Python 2.7 environment
Quickly build a python environment for deep learning and data science (Windows)
[Django] sqlite version error when running python manage.py in aws cloud9 environment
Build a "Deep learning from scratch" learning environment on Cloud9 (jupyter miniconda python3)
Build a lightweight server in Python and listen for Scratch 2 HTTP extensions
Method to build Python environment in Xcode 6
Precautions when pickling a function in python
Build Python3 and OpenCV environment on Ubuntu 18.04
Build a python environment on MacOS (Catallina)
I want to build a Python environment
Build a python virtual environment with pyenv
I created a password tool in Python.
Build a modern Python environment with Neovim
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Trial and error]
Create a Django project and application in a Python virtual environment and start the server
A complete guidebook to using pyenv, pip and python in an offline environment
Build a python environment to learn the theory and implementation of deep learning
Build a PYNQ environment on Ultra96 V2 and log in to Jupyter Notebook
Build a LAMP environment in a very short time
Create a Vim + Python test environment in 1 minute
Recommended environment and usage when developing with Python
Ubuntu18.04.05 Creating a python virtual environment in LTS
Building a python environment with virtualenv and direnv
Build a python environment with ansible on centos6
ffmpeg-Build a python environment and split the video
Build a Python environment on Mac (Mountain Lion)
I wrote a class in Python3 and Java
Create a virtual environment with conda in Python
[Python] Build a Django development environment with Docker
A memo created in a package and registered in PyPI
Create a python3 build environment with Sublime Text3
Build a Django environment with Vagrant in 5 minutes
Build a Python development environment on your Mac
Build a simple Python virtual environment without pyenv
A memo when creating a python environment with miniconda
Build a virtual environment with pyenv and venv
Think about building a Python 3 environment in a Mac environment
Work in a virtual environment with Python virtualenv.
Try using tensorflow ① Build python environment and introduce tensorflow
Build a Python environment with OSX El capitan
Build a Minecraft plugin development environment in Eclipse
Quickly build a Python Django environment with IntelliJ