AWS Cloud Formation (example 4)

Cloud Formation template

AWSTemplateFormatVersion: 2010-09-09

Parameters:
  BastionKeyName:
    Description: The EC2 Key Pair to allow SSH access to the bastion
    Type: 'AWS::EC2::KeyPair::KeyName'
  InstanceKeyName:
    Description: The EC2 Key Pair to allow SSH access to the instance
    Type: 'AWS::EC2::KeyPair::KeyName'

Resources:

  Web1Ec2Instance:
    Type: 'AWS::EC2::Instance'
    Properties:
      KeyName: !Ref InstanceKeyName
      ImageId: 'ami-035b3c7efe6d061d5'
      Tags:
      - Key: Name
        Value: !Sub ${AWS::StackName}-web-1
      UserData:
        Fn::Base64:
          !Sub |
            #!/bin/bash
            yum update -y
            yum install -y httpd24 php70 mysql56-server php70-mysqlnd
            service httpd start
            chkconfig httpd on
            groupadd www
            usermod -a -G apache ec2-user
            chown -R root:www /var/www
            chmod 2775 /var/www
            find /var/www -type d -exec sudo chmod 2775 {} \;
            find /var/www -type f -exec sudo chmod 0664 {} \;
            echo "<?php phpinfo(); ?>" > /var/www/html/index.php