LoginSignup
2
1

More than 3 years have passed since last update.

新しく作ったCloud9環境でpythonのsam buildに失敗する場合の原因と解決法

Posted at

事の発端

先日(2020年9月某日)、新しく作成したAWSのCloud9の開発環境(platform=AmazonLinux)でsam(ServerlessApplicationModel)のhello worldテンプレート(ランタイムはpython3.8)を出力し、buildやdeployを試そうと"sam build --use-container"コマンドでビルドをしてみたところ、下記のエラーに遭遇しました。
作成したばかりの素の環境でエラー(RuntimeError: Container does not exist)になったので「え??」となりました。

(↓はご参考までに、hello_worldテンプレートを出力するまで)

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/

(↓が出力したhello_worldのsam buildコマンドが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__
~(省略)~
  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

※ Cloud9については↓をご覧ください。
https://aws.amazon.com/jp/cloud9/

原因と解決法

エラーメッセージから直感的に原因がわからなかったのでAWSサポートに問い合わせたところ、

Cloud9環境のEC2インスタンスに関連付けられているEBSボリュームの容量不足が原因

との回答を頂きました。

下記のドキュメントを参考にEBSボリュームの容量を20Gに拡張することで解決しました。

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

この方法でのサイズ拡張はこちら様↓の記事でも紹介されており、とても簡単に拡張することができます。
AWS Cloud9のディスクサイズを増やす
https://qiita.com/Keisuke69/items/af87eb8629ad4249bd22

初期状態のボリュームサイズだと、特にdockerに関連する作業をCloud9上でする場合などはすぐに足りなくなりますので、resize.shを使って必要に応じて簡単にボリュームを拡張する方法は覚えておくと便利だと思います。

簡単ですが以上です。
同じ問題で困る方が減ることを願って。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1