MultiCloud Classroom notes 18/Feb/2026

Reusable Parameterized CloudFormation Template (JSON)

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "create ec2 instance with secuirt group",
    "Parameters": {
        "sgName": {
            "Description": "ec2-secuiry-group",
            "Type": "String",
            "Default": "mysq"
        },
        "vpcid": {
            "Description": "vpc id",
            "Type": "AWS::EC2::VPC::Id",
            "Default": "-"
        },
        
        "keypair": {
            "Description": "-",
            "Type": "AWS::EC2::KeyPair::KeyName",
            "Default": "-"
        }
        
        
    },
    "Resources": {
        "mysq1": {
            "Type": "AWS::EC2::SecurityGroup",
            "Properties": {
                "GroupDescription": "ec2-sq-allow-ssh-http,httpd",
                "SecurityGroupIngress": [
                    {
                        "IpProtocol": "tcp",
                        "FromPort": 80,
                        "ToPort": 80,
                        "CidrIp": "0.0.0.0/0"
                    },
                    {
                        "IpProtocol": "tcp",
                        "FromPort": 22,
                        "ToPort": 22,
                        "CidrIp": "0.0.0.0/0"
                    }
                ],
                "VpcId": {
                    "Ref": "vpcid"
                },
                "Tags": [
                    {
                        "Key": "enviroment",
                        "Value": "dev"
                    }
                ]
            }
        },
        
        "ec2instance1": {
            "Type": "AWS::EC2::Instance",
            "DependsOn": ["mysq1"],
            "Properties": {
                "KeyName": 
                { "Ref": "keypair" }
                ,
                "ImageId": "ami-0b6c6ebed2801a5cb", 
                "InstanceType": "t3.micro",
                "Monitoring": "false",
                "SecurityGroupIds" : [
                { "Ref": "mysq1" }
                ]
                ,
                "Tags": [
                    {
                        "Key": "enviroment",
                        "Value": "dev"
                    }
                ],
                "UserData": {
                    "Fn::Base64": {
                        "Fn::Join": [
                            "",
                            [
                                "#!/bin/bash -ex",
                                "sudo apt-get update && sudo apt-get install apache2 -y"
                            ]
                        ]
                    }
                }
        }
                }
    }
}

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%