使用CloudFormation文件中的apt-get安装软件包 [英] Installing packages using apt-get in CloudFormation file

查看:79
本文介绍了使用CloudFormation文件中的apt-get安装软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下CloudFormation脚本。正在创建堆栈,并启动了Ec2实例,可以使用SSH进行登录,但它没有安装软件包。

I've got the following CloudFormation script. The stack is being created and the Ec2 instance launches, and I can SSH in but it's not installing the packages.

我不确定它在哪里出现故障。我正在使用Ubuntu。我找不到实例上安装了cfn-init吗?还是仅为Amazon Linux AMI安装了它?

I'm not sure where it's failing at. I'm using Ubuntu. I can't find were cfn-init is installed on my instance? Or is it only installed for Amazon Linux AMIs?

如何解决此问题?

{
"Parameters" : {
    "ShinyKey": {
        "Description": "Key pair for instance.",
        "Type": "AWS::EC2::KeyPair::KeyName"
    }
},
"Resources": {
    "Ec2Instance" : {
        "Metadata": {
            "AWS::CloudFormation::Init": {
                "config": {
                    "packages": {
                        "apt": {
                            "r-base-dev": [],
                            "libcurl4-openssl-dev": [],
                            "git": []
                        }
                    }
                }
            }
        },
        "Type" : "AWS::EC2::Instance",
        "Properties": {
            "ImageId": "ami-9eaa1cf6",
            "InstanceType": "t2.micro",
            "KeyName": {"Ref": "ShinyKey"},
            "SecurityGroups": [{"Ref": "InstanceSecurityGroup"}],
            "Tags": [{
                "Key": "Name",
                "Value": "R-Shiny-Server"
            }],
            "UserData": {
                "Fn::Base64": {
                    "Fn::Join": [
                        "",
                        [
                            "#!/bin/bash\n",
                            "/usr/local/bin/cfn-init --region ",
                            {
                                "Ref": "AWS::Region"
                            },
                            " -s ",
                            {
                                "Ref": "AWS::StackName"
                            },
                            " -r Ec2Instance\n"
                        ]
                    ]
                }
            }
        }
    },
    "InstanceSecurityGroup" : {
        "Type" : "AWS::EC2::SecurityGroup",
        "Properties": {
            "GroupDescription" : "Enable SSH access via port 22, and ports 3838 and 80 for Shiny",
            "SecurityGroupIngress" : [
                { "IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : "0.0.0.0/0" },
                { "IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0" },
                { "IpProtocol" : "tcp", "FromPort" : "3838", "ToPort" : "3838", "CidrIp" : "0.0.0.0/0" }
            ]
        }
    }
}

}

推荐答案

上面的模板的问题是 cfn-init 未安装在Ubuntu AMI中,因此对 cfn-init的调用在您的用户数据脚本中将返回逗号

The issue with the template above is that cfn-init is not installed in the Ubuntu AMI, so the call to cfn-init in your user-data script will return "command not found" and do nothing.

仅在最新的Amazon Linux AMI中自动安装cfn-helper实用程序,如文档。对于Ubuntu,您需要手动安装它们,可以通过在#!/ bin / bash\n,:

The cfn-helper utilities are automatically installed only in the latest Amazon Linux AMI, as noted in the documentation. For Ubuntu you need to install them manually, which you can do by adding a line to your existing user-data script, after "#!/bin/bash\n",:

"apt-get update && apt-get install pip && pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n",

此后,对下一行 / usr / local / bin / cfn-init 的调用应正确运行。

After this, the call to /usr/local/bin/cfn-init in the next line should run correctly.

这篇关于使用CloudFormation文件中的apt-get安装软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆