Following YML script can be use to perform Windows EC2 deployment using cloud formation.
Parameters: EnvironmentType: Description: Environment Type Type: String AllowedValues: [development, production] ConstraintDescription: must be development or production KeyName: Description: Name of an existing EC2 KeyPair to RDP this windows instance. Type: AWS::EC2::KeyPair::KeyName ConstraintDescription: must be the name of an existing EC2 KeyPair. Mappings: EnvironmentToInstanceType: development: instanceType: t2.micro production: instanceType: t2.small Resources: ServerSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Allow RDP & HTTP access from all IP ADDresses SecurityGroupIngress: - IpProtocol: tcp FromPort: 80 ToPort: 80 CidrIp: 0.0.0.0/0 - IpProtocol: tcp FromPort: 3289 ToPort: 3289 CidrIp: 0.0.0.0/0 WindowsInstance: Type: AWS::EC2::Instance Properties: InstanceType: !FindInMap [EnvironmentToInstanceType, !Ref 'EnvironmentType', instanceType] #Choose correct ImageID, ami-da003ebf belogs to base windows 2012 R2 image. ImageId: ami-da003ebf KeyName: !Ref KeyName SecurityGroups: - !Ref ServerSecurityGroup
Here are the steps.
- Save above code in WinEC2.YML file.
- Open AWS management console, In Cloud formation section, select New Template, select Upload a template to Amazon S3. Select WinEC2.YML file then follow the wizard with all default options. You will be prompted for Environment Type (Production/Development) & Key Pair.
- Once deployment successfully completes, you would see events like below screenshot.
If you wish to join newly created windows EC2 to Active directory then use following reference for YML code. https://aws.amazon.com/blogs/security/how-to-configure-your-ec2-instances-to-automatically-join-a-microsoft-active-directory-domain/