DEV Community

Cover image for Troubleshooting AWS Cloud9 - RuntimeError: Container does not exist / No space left on device
Samira Yusifova
Samira Yusifova

Posted on

Troubleshooting AWS Cloud9 - RuntimeError: Container does not exist / No space left on device

Issue description

Recently I got a runtime error in AWS Cloud9 while trying to build my serverless application as a Docker container image. I used AWS SAM build command:

sam build --use-container
Enter fullscreen mode Exit fullscreen mode

As a result I got the following error issue:

RuntimeError: Container does not exist. Cannot get logs for this container

It turned out, AWS tried to create amazon/aws-sam-cli-build-image-python3.8 Docker container image:

Alt Text

but failed:

Alt Text

Then I tried to pull the image manually using docker command:

docker pull amazon/aws-sam-cli-build-image-python3.8
Enter fullscreen mode Exit fullscreen mode

but it looks like there is not enough disk space:

Alt Text

You can use the following command to verify that the root volume mounted under "/" is full:

df -h
Enter fullscreen mode Exit fullscreen mode

Here is an output with 95% out of 10 GiB of EBS storage (/dev/xvda1) is used:

Alt Text

To check whether the EBS volume has a partition that must be extended, use the following command:

lsblk
Enter fullscreen mode Exit fullscreen mode

It displays information about the block devices attached to your instance.

Alt Text

Solution

Once the problem is understood, improvement comes naturally. All I need is to increase the size of my EBS volume.

πŸ‘‰ Step 1. Open a new file in Cloud9

Alt Text

πŸ‘‰ Step 2. Add the script below to the file:

#!/bin/bash

# Specify the desired volume size in GiB as a command-line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}

# Get the ID of the environment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)

# Get the ID of the Amazon EBS volume associated with the instance.
VOLUMEID=$(aws ec2 describe-instances \
  --instance-id $INSTANCEID \
  --query "Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId" \
  --output text)

# Resize the EBS volume.
aws ec2 modify-volume --volume-id $VOLUMEID --size $SIZE

# Wait for the resize to finish.
while [ \
  "$(aws ec2 describe-volumes-modifications \
    --volume-id $VOLUMEID \
    --filters Name=modification-state,Values="optimizing","completed" \
    --query "length(VolumesModifications)"\
    --output text)" != "1" ]; do
sleep 1
done

#Check if we're on an NVMe filesystem
if [ $(readlink -f /dev/xvda) = "/dev/xvda" ]
then
  # Rewrite the partition table so that the partition takes up all the space that it can.
  sudo growpart /dev/xvda 1

  # Expand the size of the file system.
  # Check if we are on AL2
  STR=$(cat /etc/os-release)
  SUB="VERSION_ID=\"2\""
  if [[ "$STR" == *"$SUB"* ]]
  then
    sudo xfs_growfs -d /
  else
    sudo resize2fs /dev/xvda1
  fi

else
  # Rewrite the partition table so that the partition takes up all the space that it can.
  sudo growpart /dev/nvme0n1 1

  # Expand the size of the file system.
  # Check if we're on AL2
  STR=$(cat /etc/os-release)
  SUB="VERSION_ID=\"2\""
  if [[ "$STR" == *"$SUB"* ]]
  then
    sudo xfs_growfs -d /
  else
    sudo resize2fs /dev/nvme0n1p1
  fi
fi 
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ Step 3. Save the file as resize.sh (press Ctrl + S)

Alt Text

πŸ‘‰ Step 4. Run sh-file (shell script):

sh resize.sh 20
Enter fullscreen mode Exit fullscreen mode

You should get detailed information about data block changes:

Alt Text

Here is the link to AWS instuction.

Results

To verify a new EBS volume size, run df -h command again:

Alt Text

Once there is enough disk space for Docker, my container issue is resolved:

Alt Text

Hopefully, this solution could save you both some time and headaches.

Top comments (0)