Archive

Archive for April, 2020

CloudFormation JSON script to create EC2 Instance in AWS

April 16, 2020 Leave a comment

Json script as follows;

———————————————————————————————————————————

{“Description”: “CloudFormation template for creating an ec2 instance”,
“Parameters”: {
“KeyName”: {
“Description”: “Key Pair name”,
“Type”: “AWS::EC2::KeyPair::KeyName”,
“Default”:”CFEC2KP”
},
“VPC”: {
“Type”: “AWS::EC2::VPC::Id”,
“Default”:”vpc-9d7773e7″
},
“Subnet”:{
“Type”: “AWS::EC2::Subnet::Id”,
“Default”: “subnet-a46d9a85”
},
“InstanceType”: {
“Description”: “Select one of the possible instance types”,
“Type”: “String”,
“Default”: “t2.micro”
},
“SecurityGroup”:{
“Type”: “AWS::EC2::SecurityGroup::Id”,
“Default” : “sg-751ee55a”
}
},
“Resources”:{
“Server”: {
“Type”: “AWS::EC2::Instance”,
“Properties”: {
“ImageId”: “ami-0323c3dd2da7fb37d”,
“InstanceType”: {“Ref”: “InstanceType”},
“KeyName”: {“Ref”: “KeyName”},
“SecurityGroupIds”: [{“Ref”: “SecurityGroup”}],
“Tags”: [{“Key”: “Server”,”Value”: “TestServer”}],
“SubnetId”: {“Ref”: “Subnet”}
}
}
},
“Outputs”: {
“PublicName”: {
“Value”: {“Fn::GetAtt”: [“Server”, “PublicDnsName”]},
“Description”: “Public name (connect via SSH)”
}
}
}


Note: Create keypair via AWS console and enter the name in parameter section