From 7a3474a139293d89dacca7252eb9c6bcc52d8593 Mon Sep 17 00:00:00 2001 From: Martin Cholewa Date: Tue, 21 Jan 2025 17:41:47 +0100 Subject: [PATCH] create_ec2_instance with keypair and allow ssh from anywhere --- 01_ec2.yaml | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/01_ec2.yaml b/01_ec2.yaml index aa69c5c..582b415 100644 --- a/01_ec2.yaml +++ b/01_ec2.yaml @@ -1,9 +1,37 @@ AWSTemplateFormatVersion: 2010-09-09 -Description: Part 1 - Build a webapp stack with CloudFormation +Description: Building EC2 Instance using CloudFormation Resources: - WebAppInstance: - Type: AWS::EC2::Instance + + DefaultSecurityGroupIngress: + Type: 'AWS::EC2::SecurityGroupIngress' + Properties: + GroupId: sg-04979a7901ebe5c37 + IpProtocol: tcp + FromPort: 22 + ToPort: 22 + CidrIp: 0.0.0.0/0 + + KeyPair: + Type: 'AWS::EC2::KeyPair::KeyName' + Properties: + KeyName: existing-key-pair-name + + ChoseEC2: + Type: 'AWS::EC2::Instance' + DependsOn: KeyPair Properties: ImageId: ami-0df8c184d5f6ae949 InstanceType: t2.micro + KeyName: !Ref KeyPair + SecurityGroupIds: + - sg-04979a7901ebe5c37 + +Outputs: + LabInstanceId: + Description: Instance Id + Value: !Ref ChoseEC2 + + LabInstancePublicIP: + Description: Public IP address of the instance + Value: !GetAtt ChoseEC2.PublicIp