ec2 instance.yml

This commit is contained in:
minakshi 2024-11-10 21:03:45 +05:30 committed by GitHub
parent 20720ca4f9
commit f389974cdb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 55 additions and 0 deletions

55
ec2 instance.yml Normal file
View File

@ -0,0 +1,55 @@
AWS TemplateFormatVersion:
'2010-09-09'
Description: CloudFormation template to provision EC2 instances for hosting an application
Parameters:
Instance type:
Description: EC2 instance types
Type: String
Default: t2.micro
Allowed values:
:t2.micro
:t2.small
:t2.medium
ConstantDescription: Must be a valid EC2 instance type
Key name:
Description: Name of an existing EC2 key pair to enable SSH access to the instances
Type: AWS::EC2::KeyPair::Keyname
Resources:
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
Group Description: Enable SSH and HTTP access
VpcId:
SecurityGroupIngress:
IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp:0.0.0.0/0
MyEC2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType:
KeyName:
ImageId:ami-0c5551bh4bnh
SecurityGroupIds:
InstanceSecurityGroup
UserData:
Fn::Base64: |
#!/bin/bash
yum update-y
yum install-y httpd
systemctl start httpd
systemctl enable httpd
echo"<h1>Hello from EC2!</H1>">/var/www/html/index.html
Outputs:
InstancePublicIp:
Description:Public Ip of the EC2 INSTANCE
Value:MyEC2Instance.PublicIp
InstanceId:
Description:InstanceID OF THE ec2 instance
Value:MyEC2Instance