AWSTemplateFormatVersion: '2010-09-09' Metadata: License: Apache-2.0 Description: 'AWS CloudFormation Sample Template for cfn-guard blog, for developers. It creates an Amazon EC2 instance running the latest Amazon Linux AMI, based on the region in which the stack is run, with restricted sizes. It also creates an EC2 security group for the instance to give you SSH access on a non-standard port. **WARNING** This template creates an Amazon EC2 instance, and you will be billed for it once the stack is deployed. Delete the stack after you have completed your tests to avoid additional charges' Parameters: KeyName: Description: Name of an existing EC2 KeyPair to enable SSH access to the instance Type: AWS::EC2::KeyPair::KeyName ConstraintDescription: must be the name of an existing EC2 KeyPair. SSHLocation: Description: The IP address range that can be used to SSH to the EC2 instances Type: String MinLength: 9 MaxLength: 18 Default: 0.0.0.0/0 AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) ConstraintDescription: Must be a company approved, valid IP CIDR range of the form x.x.x.x/x. LatestAmiId: Type: 'AWS::SSM::Parameter::Value' Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2' Resources: EC2Instance: Type: AWS::EC2::Instance Properties: InstanceType: t3.medium SecurityGroups: [!Ref 'InstanceSecurityGroup'] KeyName: !Ref 'KeyName' ImageId: !Ref 'LatestAmiId' InstanceSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Enable SSH access via custom port 33322 SecurityGroupIngress: - IpProtocol: tcp FromPort: 22 ToPort: 22 CidrIp: !Ref 'SSHLocation' NewVolume: Type: AWS::EC2::Volume Properties: Size: 512 AvailabilityZone: !GetAtt [EC2Instance, AvailabilityZone] Outputs: InstanceId: Description: InstanceId of the newly created EC2 instance Value: !Ref 'EC2Instance' AZ: Description: Availability Zone of the newly created EC2 instance Value: !GetAtt [EC2Instance, AvailabilityZone] PublicDNS: Description: Public DNSName of the newly created EC2 instance Value: !GetAtt [EC2Instance, PublicDnsName] PublicIP: Description: Public IP address of the newly created EC2 instance Value: !GetAtt [EC2Instance, PublicIp]