Parameters: MyKeyPair: Description: Select the Key Pair you wish to use for these instances. Type: AWS::EC2::KeyPair::KeyName # Optional, but handy Default: MyDefaultKeyPair Resources: # Define the Security Group MySecurityGroupId: Type: AWS::EC2::SecurityGroup Properties: GroupName: My Security Group Name GroupDescription: My Security Group Description SecurityGroupIngress: - IpProtocol: icmp FromPort: -1 ToPort: -1 CidrIp: 0.0.0.0/0 - IpProtocol: tcp FromPort: 22 ToPort: 22 CidrIp: 0.0.0.0/0 - IpProtocol: tcp FromPort: 80 ToPort: 80 CidrIp: 0.0.0.0/0 Tags: - Key: Name Value: My CF Security Group # Define the EC2 Instance MyEc2Instance: Type: AWS::EC2::Instance Properties: ImageId: ami-710e2414 InstanceType: t2.micro # Optional, but required if you want to actually access it. KeyName: !Ref MyKeyPair # Use the Security Group created above SecurityGroups: - !Ref MySecurityGroupId Tags: - Key: Name Value: My EC2 Instance # These lines initialize the use of ::Init. Init will not function without them. UserData: Fn::Base64: !Sub | #!/bin/bash -xe /opt/aws/bin/cfn-init -s ${AWS::StackId} -r MyEc2Instance --region ${AWS::Region} || error_exit 'Failed to run cfn-init' # Add the Metadata commands to install Apache and PHP # Notice this section is outside of the Properties section. Metadata: AWS::CloudFormation::Init: config: # Install Apache and PHP at their current versions packages: yum: httpd: [] php: [] # Start Apache and configure to restart at reboot services: sysvinit: httpd: enabled: true ensureRunning: true files: "/var/www/html/index.php": content: !Sub |

Hello!

I'm glad you made it!
You just created a Cloud Formation stack called: ${AWS::StackName}!
mode: '000400' owner: apache group: apache