LoginSignup
2
0

More than 5 years have passed since last update.

OpsWorks Instancesで起動したEC2から作成したカスタムAMIをOpsWorks Instancesで利用する際の注意点

Last updated at Posted at 2016-11-14

1. はじめに

  • OpsWorks Instances で起動した EC2 をイメージ(AMI)化して、それを OpsWorks Instances のカスタムAMIとして利用する際の注意点。
  • EC2は、"Amazon Linux 2016.09", "Amazon Linux instance Chef 12 stack", "Amazon EBS-backed" で作成している。
  • 下記の作法の通りに作成していないカスタムAMIを利用して OpsWorks Instances で EC2 を起動すると、Status が "running_setup" 中のままとなり、作成が完了しない。

2. OpsWorks Instances で起動した EC2 から カスタムAMI を作成する

(参考:本家ドキュメント → "To create a custom AMI from an AWS OpsWorks instance")
* AMI を作成する EC2 を起動した OpwsWorks Layers の "Auto healing enabled" を "No" へ変更する

  • AMI を作成する EC2 へ SSH ログインして、次のコマンドを実行する
$ sudo /etc/init.d/monit stop

$ sudo /etc/init.d/opsworks-agent stop

$ sudo rm -rf /etc/aws/opsworks/
$ sudo rm -rf /opt/aws/opsworks/
$ sudo rm -rf /var/log/aws/opsworks/
$ sudo rm -rf /var/lib/aws/opsworks/
$ sudo rm -rf /var/lib/cloud/
$ sudo rm -rf /etc/chef
$ sudo rm -rf /var/chef
$ sudo rm -rf /opt/chef
$ sudo rm -f /etc/monit.d/opsworks-agent.monitrc
$ sudo rm -f /etc/monit/conf.d/opsworks-agent.monitrc

$ sudo rpm -e opsworks-agent-ruby
$ sudo rpm -e chef
  • OpsWorks のコンパネから、AMI を作成する EC2 インスタンスを停止(Actions:stop)する

    Status が stopped となったことを確認

  • イメージ(AMI)を作成する

3. OpsWorks Instance でカスタムAMI から EC2 を起動する CloudFormation の例

"Resources": {
    "OpsWorksStack": {
        "Type": "AWS::OpsWorks::Stack",
        "Properties": {
            "Name": "example",
            "ConfigurationManager": {
                "Name": "Chef",
                "Version": "12"
            },
            "VpcId": "vpc-********",
            "DefaultSubnetId": "subnet-********",
            "DefaultInstanceProfileArn": "arn:aws:iam::************:instance-profile/**********",
            "ServiceRoleArn": "arn:aws:iam::************:role/**********",
            "DefaultOs": "Custom",
            "DefaultRootDeviceType": "ebs",
            "DefaultSshKeyName": "aws-tonishy",
            "HostnameTheme": "Layer_Dependent",
            "UseOpsworksSecurityGroups": "false"
        }
    },
    "OpsWorksLayer": {
        "Type": "AWS::OpsWorks::Layer",
        "Properties": {
            "Type": "custom",
            "Name": "example",
            "Shortname": "example",
            "StackId": {
                "Ref": "OpsWorksStack"
            },
            "EnableAutoHealing": "true",
            "AutoAssignPublicIps": "true",
            "AutoAssignElasticIps": "false",
            "CustomSecurityGroupIds": [
                "sg-********"
            ],
            "CustomInstanceProfileArn": "arn:aws:iam::************:instance-profile/**********"
        }
    },
    "OpsWorksInstance": {
        "Type": "AWS::OpsWorks::Instance",
        "Properties": {
            "AmiId": "ami-********",
            "Os": "Custom",
            "StackId": {
                "Ref": "OpsWorksStack"
            },
            "LayerIds": [
                {
                    "Ref": "OpsWorksLayer"
                }
            ],
            "InstanceType": "t2.micro"
        }
    }
}

※ AWS::OpsWorks::Instance の AmiId に、カスタムAMIの id を設定する

2
0
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
0