pilasguru

CloudFormation: 2 instances with Docker

Jun 22nd, 2021
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.40 KB | None | 0 0
  1. AWSTemplateFormatVersion: "2010-09-09"
  2. Metadata:
  3.   License: Apache-2.0
  4. Description: "Create an AWS EC2 instance running the AWS Linux AMI."
  5. Parameters:
  6.   KeyName:
  7.     Description: Name of an existing EC2 KeyPair
  8.     Type: AWS::EC2::KeyPair::KeyName
  9.     ConstraintDescription: must be the name of an existing EC2 KeyPair.
  10.  
  11. Resources:
  12.   Docker01:
  13.     Type: AWS::EC2::Instance
  14.     Properties:
  15.       InstanceType: t2.micro
  16.       SecurityGroups: [!Ref "InstanceSecurityGroup"]
  17.       KeyName: !Ref "KeyName"
  18.       ImageId: ami-0aeeebd8d2ab47354   # us-east-1
  19.       UserData:
  20.        !Base64 |
  21.          #!/bin/bash -xe
  22.           amazon-linux-extras install -y docker=latest
  23.           systemctl enable --now docker.service
  24.           curl -s https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh
  25.           usermod -a -G docker ec2-user
  26.       Tags:
  27.       - Key: Name
  28.         Value: docker-01
  29.  
  30.   Docker02:
  31.     Type: AWS::EC2::Instance
  32.     Properties:
  33.       InstanceType: t2.micro
  34.       SecurityGroups: [!Ref "InstanceSecurityGroup"]
  35.       KeyName: !Ref "KeyName"
  36.       ImageId: ami-0aeeebd8d2ab47354   # us-east-1
  37.       UserData:
  38.        !Base64 |
  39.          #!/bin/bash -xe
  40.           amazon-linux-extras install -y docker=latest
  41.           systemctl enable --now docker.service
  42.           curl -s https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh
  43.           usermod -a -G docker ec2-user
  44.       Tags:
  45.       - Key: Name
  46.         Value: docker-02
  47.  
  48.   InstanceSecurityGroup:
  49.     Type: AWS::EC2::SecurityGroup
  50.     Properties:
  51.       GroupDescription: Enable SSH access on port 22
  52.       SecurityGroupIngress:
  53.         - IpProtocol: tcp
  54.           FromPort: 22
  55.           ToPort: 22
  56.           CidrIp: "0.0.0.0/0"
  57.  
  58. Outputs:
  59.   PublicDNS01:
  60.     Description: Public DNS Name of the newly created AWS EC2 instance
  61.     Value: !GetAtt [Docker01, PublicDnsName]
  62.   PublicIP01:
  63.     Description: Public IP address of the newly created AWS EC2 instance
  64.     Value: !GetAtt [Docker01, PublicIp]
  65.   PublicDNS02:
  66.     Description: Public DNS Name of the newly created AWS EC2 instance
  67.     Value: !GetAtt [Docker02, PublicDnsName]
  68.   PublicIP02:
  69.     Description: Public IP address of the newly created AWS EC2 instance
  70.     Value: !GetAtt [Docker02, PublicIp]
Add Comment
Please, Sign In to add comment