Parameters: MyKeyPair: Description: Select the Key Pair you wish to use for these instances. Type: AWS::EC2::KeyPair::KeyName # Optional, but handy Default: hello DBName: AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*' ConstraintDescription: must begin with a letter and contain only alphanumeric characters. Default: wordpressdb Description: The WordPress database name MinLength: 4 MaxLength: 64 Type: String DBPassword: AllowedPattern: '[a-zA-Z0-9]*' ConstraintDescription: must contain only alphanumeric characters. Description: The WordPress database admin account password MaxLength: 41 MinLength: 8 NoEcho: true Type: String Default: wordpressdb DBRootPassword: AllowedPattern: '[a-zA-Z0-9]*' ConstraintDescription: must contain only alphanumeric characters. Description: MySQL root password MaxLength: 41 MinLength: 8 NoEcho: true Type: String Default: wordpressdb DBUser: AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*' ConstraintDescription: must begin with a letter and contain only alphanumeric characters. Description: The WordPress database admin account username MaxLength: 16 MinLength: 1 NoEcho: true Type: String Default: wordpressdb 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 -c InstallCode -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: configSets: InstallCode: - First - Second #default: #configSet: "InstallCode" # Install Apache and PHP at their current versions First: packages: yum: httpd: [] telnet: [] php: [] #mariadb: [] mariadb-server: [] php-mysql: [] # Start Apache and configure to restart at reboot services: sysvinit: # Need to be in this order. I do not know why mariadb: enabled: true ensureRunning: true httpd: enabled: true ensureRunning: true files: "/var/www/html/index.php": content: !Sub |