Esempio n. 1
0
    public WebserverStack()
    {
        var group = new SecurityGroup("web-secgrp", new SecurityGroupArgs
        {
            Ingress =
            {
                // Uncomment to fail a test:
                // new SecurityGroupIngressArgs { Protocol = "tcp", FromPort = 22, ToPort = 22, CidrBlocks = { "0.0.0.0/0" } },
                new SecurityGroupIngressArgs {
                    Protocol = "tcp", FromPort = 80, ToPort = 80, CidrBlocks ={ "0.0.0.0/0"                                   }
                }
            }
        });

        var amiId = GetAmi
                    .Invoke(new GetAmiInvokeArgs
        {
            MostRecent = true,
            Owners     = "099720109477",
            Filters    =
            {
                new GetAmiFilterInputArgs
                {
                    Name   = "name",
                    Values = "ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*",
                }
            }
        })
                    .Apply(ami => ami.Id);

        // var userData = "#!/bin/bash echo \"Hello, World!\" > index.html nohup python -m SimpleHTTPServer 80 &";

        var server = new Instance("web-server-www", new InstanceArgs
        {
            InstanceType        = "t2.micro",
            VpcSecurityGroupIds = { group.Id }, // reference the group object above
            Ami = amiId,
            // Comment out to fail a test:
            Tags = { { "Name", "webserver" } },
            // Uncomment to fail a test:
            // UserData = userData           // start a simple webserver
        });
    }
Esempio n. 2
0
    public WebServerStack()
    {
        var ami = GetAmi.Invoke(new GetAmiInvokeArgs
        {
            MostRecent = true,
            Owners     = { "137112412989" },
            Filters    = { new GetAmiFilterInputArgs {
                               Name = "name", Values = "amzn-ami-hvm-*"
                           } }
        });

        var group = new SecurityGroup("web-secgrp", new SecurityGroupArgs
        {
            Description = "Enable HTTP access",
            Ingress     =
            {
                new SecurityGroupIngressArgs
                {
                    Protocol   = "tcp",
                    FromPort   = 80,
                    ToPort     = 80,
                    CidrBlocks ={ "0.0.0.0/0"                  }
                }
            }
        });

        var userData = @"
#!/bin/bash
echo ""Hello, World!"" > index.html
nohup python -m SimpleHTTPServer 80 &
";

        var server = new Instance("web-server-www", new InstanceArgs
        {
            InstanceType        = Size,
            VpcSecurityGroupIds = { group.Id },
            UserData            = userData,
            Ami = ami.Apply(a => a.Id)
        });

        this.PublicIp  = server.PublicIp;
        this.PublicDns = server.PublicDns;
    }