AWSTemplateFormatVersion: 2010-09-09 Description: >- This template creates an EC2 instance that installs a .NET application on launch. Parameters: WindowsAMIId: Description: >- Use the below value to automatically look up the latest published AMI ID for Windows Server 2019, or supply your own. Type: AWS::SSM::Parameter::Value Default: '/aws/service/ami-windows-latest/Windows_Server-2019-English-Core-Base' Resources: AppServerSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Enable HTTP and RDP SecurityGroupIngress: - IpProtocol: tcp FromPort: 80 ToPort: 80 CidrIp: 0.0.0.0/0 AppServerEIP: Type: AWS::EC2::EIP Properties: InstanceId: Ref: AppServer AppServer: Type: AWS::EC2::Instance Metadata: AWS::CloudFormation::Init: config: files: 'c:\cfn\cfn-hup.conf': content: !Sub | [main] stack=${AWS::StackId} region=${AWS::Region} 'c:\cfn\hooks.d\cfn-auto-reloader.conf': content: !Sub | [cfn-auto-reloader-hook] triggers=post.update path=Resources.AppServer.Metadata.AWS::CloudFormation::Init action=cfn-init.exe -v -s ${AWS::StackId} -r AppServer --region ${AWS::Region} 'C:\AppServer\ASPNETCoreDemo.zip': source: 'http://s3.amazonaws.com/us-east-1.andyhoppatamazon.com/samples/ASPNETCoreDemo.zip' 'C:\DotNet\aspdotnet-3.1-installer.exe': source: 'https://download.visualstudio.microsoft.com/download/pr/9b9f4a6e-aef8-41e0-90db-bae1b0cf4e34/4ab93354cdff8991d91a9f40d022d450/dotnet-hosting-3.1.6-win.exe' commands: 1-install-aspdotnet: command: C:\DotNet\aspdotnet-3.1-installer.exe /install /quiet /norestart 2-extract-appserver: command: 'powershell.exe /c "Expand-Archive C:\AppServer\ASPNetCoreDemo.zip C:\AppServer\ "' 3-install-service: command: >- sc.exe create ASPNETCoreDemo binPath="C:\AppServer\ASPNETCoreDemo.exe --service --urls http://+:80" 4-start-service: command: 'sc.exe start ASPNETCoreDemo' 5-open-http-port: command: 'netsh advfirewall firewall add rule name="ASPNetCoreDemo" dir=in action=allow protocol=TCP localport=80' services: windows: cfn-hup: enabled: 'true' ensureRunning: 'true' files: - 'c:\cfn\cfn-hup.conf' - 'c:\cfn\hooks.d\cfn-auto-reloader.conf' Properties: InstanceType: t3.micro ImageId: !Ref WindowsAMIId SecurityGroups: [!Ref AppServerSecurityGroup] UserData: Fn::Base64: !Sub - | - EncodedAppServerWaitHandle: Fn::Base64: !Ref AppServerWaitHandle AppServerWaitHandle: Type: AWS::CloudFormation::WaitConditionHandle AppServerWaitCondition: Type: AWS::CloudFormation::WaitCondition DependsOn: AppServer Properties: Handle: !Ref AppServerWaitHandle Timeout: 600 Outputs: AppServerURL: Value: !Sub "http://${AppServerEIP}" Description: >- Application server URL.