我已经创建了一个现有VPC。如何使用该VPC并通过云形成创建Ec2实例?我试图添加安全组,但失败了。
在我带有安全组的ec2实例的云形成模板下面。我试图添加一个现有的VPC。例如,我可以指向Example(MYVPC),以便在创建时将使用MYVPC创建一个ec2实例
云的形成:
Resources:
AppNode:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-a58d0dc5
KeyName: aws-key1
SecurityGroups:
- !Ref AppNodeSG
UserData: !Base64 |
#!/bin/bash
apt-get update -qq
apt-get install -y apt-transport-https ca-certificates
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --
recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" |
tee /etc/apt/sources.list.d/docker.list
apt-get update -qq
apt-get purge lxc-docker || true
apt-get -y install linux-image-extra-$(uname -r) linux-image-extra-
virtual
apt-get -y install docker-engine
usermod -aG docker ubuntu
mkdir -p /etc/systemd/system/docker.service.d
printf "[Service]\nExecStart=\nExecStart=/usr/bin/dockerd -H fd://
-H tcp://0.0.0.0:2375\n" >>
/etc/systemd/system/docker.service.d/docker.conf
systemctl daemon-reload
systemctl restart docker
AppNodeSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: for the app nodes that allow ssh, http and
docker ports
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '2375'
ToPort: '2375'
CidrIp: 0.0.0.0/0