LoginSignup
3
1

More than 3 years have passed since last update.

EC2 Image Builderのコンポーネントをサクッと作る

Last updated at Posted at 2020-01-02

はじめに

Image Builder試してみたけど、インストールしたいパッケージのComponentsがない。
このためにドキュメント調べるのか。。メンドイ
ってなった事はないだろうか?私はある。

AWSのComponentsをベースに作る

AWSで用意してあるComponentsをベースに、ちょっと変えるだけ。
単純にインストールするだけなら難しくない。

1. ベースのComponentsをコピペ

Componentsにpython-3-linuxという物があるので、それを使うといい。

name: Python 3
description: Install the latest version of Python 3.
schemaVersion: 1.0
phases:
  - name: build
    steps:
      - name: InstallPython3
        action: ExecuteBash
        inputs:
          commands:
            - sudo yum install python3 -y

  - name: validate
    steps:
      - name: ValidatePython3
        action: ExecuteBash
        inputs:
          commands:
            - |
              if type -P python3 &>/dev/null; then
                  echo "The python3 command exists."
              else
                  echo "The python3 command does not exist. Failing."
                  exit 1
              fi

              python3 --version
              if [[ $? == 0 ]]; then
                  echo "python3 was successfully invoked."
              else
                  echo "python3 could not be invoked. Failing."
                  exit 1
              fi

2. インストールしたいものに合わせる

Gitをyumでインストールしてみる。

# Python 3となっている箇所を変える
name: Git
description: Install the latest version of Git.
schemaVersion: 1.0
phases:
  - name: build
    steps:
      # Python3となっている箇所を変える
      - name: InstallGit
        action: ExecuteBash
        inputs:
          commands:
            # インストールコマンドを入れる
            - sudo yum install git -y

  - name: validate
    steps:
      - name: ValidateGit
        action: ExecuteBash
        inputs:
          commands:
           # python3となっている箇所を変える
           - |             
              if type -P git &>/dev/null; then
                  echo "The git command exists."
              else
                  echo "The git command does not exist. Failing."
                  exit 1
              fi

              git --version
              if [[ $? == 0 ]]; then
                  echo "git was successfully invoked."
              else
                  echo "git could not be invoked. Failing."
                  exit 1
              fi

これだけ!
あとはコンポーネントに反映して、パイプライン作ってテストすれば良い。

補足

python-3-linuxは、単に最新バージョンをインストールして確認するだけだが、他にも処理を入れるなら以下あたりが参考になりそう。

  • バージョン判定を行う
    php-7_3-linux
  • systemctl enableする
    docker-ce-linux

ドキュメントは以下にある。
https://docs.aws.amazon.com/imagebuilder/latest/userguide/managing-image-builder-console.html#image-builder-application-documents

EC2 Image Builderとは(一応説明)

AMI作成を自動化してくれるツール(パッケージインストール等をやってくれる)。

Developers.IO:EC2のイメージ作成を劇的に効率化するEC2 Image Builderが発表されました! #reinvent
Qiita:EC2 Image Builder を触ってみました。

3
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
3
1