Exemple #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
        });
    }
Exemple #2
0
    public WebServerStack()
    {
        var ami = Output.Create(GetAmi.InvokeAsync(new GetAmiArgs
        {
            MostRecent = true,
            Owners     = { "137112412989" },
            Filters    = { new GetAmiFilterArgs {
                               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;
    }
        public WebECBackendStack()
        {
            var ami = Output.Create(GetAmi.InvokeAsync(new GetAmiArgs
            {
                MostRecent = true,
                Owners     = { AwsId },
                Filters    =
                {
                    new GetAmiFilterArgs
                    {
                        Name   = "name",
                        Values ={ AmiName              },
                    },
                },
            }));

            var group = new SecurityGroup("experience-capture-security-group", new SecurityGroupArgs
            {
                Description = "Enable HTTP access",
                Ingress     =
                {
                    CreateIngressRule(22),  // SSH
                    CreateIngressRule(80),  // HTTP
                    CreateIngressRule(443), // HTTPS
                },
                Egress =
                {
                    new SecurityGroupEgressArgs // Allow all outbound traffic
                    {
                        Protocol   = "-1",
                        FromPort   = 0,
                        ToPort     = 0,
                        CidrBlocks ={ "0.0.0.0/0"                  },
                    },
                },
            });

            var server = new Instance("experience-capture-cloud", new InstanceArgs
            {
                InstanceType        = Ec2Size,
                VpcSecurityGroupIds = { group.Name },
                Ami = ami.Apply(a => a.Id),
                AssociatePublicIpAddress = false,
            });

            string elasticId;

            if (IsProduction == "production")
            {
                elasticId = IpIdProduction;
            }
            else
            {
                elasticId = IpIdStaging;
            }

            var elasticIp = new EipAssociation("experience-capture-ip", new EipAssociationArgs
            {
                AllocationId = elasticId,
                InstanceId   = server.Id,
            });

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