Search in sources :

Example 36 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestRDSPostgres method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String clientStackName = "client-" + this.random8String();
    final String stackName = "rds-postgres-" + this.random8String();
    final String password = this.random8String();
    try {
        this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml");
        try {
            this.createStack(context, clientStackName, "state/client-sg.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName));
            try {
                this.createStack(context, stackName, "state/rds-postgres.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentClientStack").withParameterValue(clientStackName), new Parameter().withParameterKey("DBName").withParameterValue("db1"), new Parameter().withParameterKey("DBMasterUserPassword").withParameterValue(password));
            // TODO how can we check if this stack works? start a bastion host and try to connect?
            } finally {
                this.deleteStack(context, stackName);
            }
        } finally {
            this.deleteStack(context, clientStackName);
        }
    } finally {
        this.deleteStack(context, vpcStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 37 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestVPCSshBastion method test.

@Test
public void test() {
    final Context context = new Context();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String bastionStackName = "vpc-ssh-bastion-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    try {
        final KeyPair key = this.createKey(keyName);
        try {
            this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
            try {
                this.createStack(context, bastionStackName, "vpc/vpc-ssh-bastion.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("KeyName").withParameterValue(keyName));
                final String host = this.getStackOutputValue(bastionStackName, "IPAddress");
                this.probeSSH(context, host, key);
            } finally {
                this.deleteStack(context, bastionStackName);
            }
        } finally {
            this.deleteStack(context, vpcStackName);
        }
    } finally {
        this.deleteKey(context, keyName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) KeyPair(com.amazonaws.services.ec2.model.KeyPair) Parameter(com.amazonaws.services.cloudformation.model.Parameter) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 38 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestWordpressHA method testMySQL.

@Test
public void testMySQL() {
    final Context context = new Context();
    final String zoneStackName = "zone-" + this.random8String();
    final String vpcStackName = "vpc-2azs-" + this.random8String();
    final String stackName = "wordpress-ha-" + this.random8String();
    final String classB = "10";
    final String keyName = "key-" + this.random8String();
    final String subDomainName = stackName;
    final String blogTitle = "Stay-AWSome";
    final String blogPassword = this.random8String();
    try {
        this.createKey(keyName);
        try {
            this.createStack(context, zoneStackName, "vpc/zone-legacy.yaml", new Parameter().withParameterKey("HostedZoneName").withParameterValue(Config.get(Config.Key.DOMAIN_SUFFIX)), new Parameter().withParameterKey("HostedZoneId").withParameterValue(Config.get(Config.Key.HOSTED_ZONE_ID)));
            try {
                this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue(classB));
                try {
                    this.createStack(context, stackName, "wordpress/wordpress-ha.yaml", new Parameter().withParameterKey("ParentVPCStack").withParameterValue(vpcStackName), new Parameter().withParameterKey("ParentZoneStack").withParameterValue(zoneStackName), new Parameter().withParameterKey("WebServerKeyName").withParameterValue(keyName), new Parameter().withParameterKey("SubDomainNameWithDot").withParameterValue(subDomainName + "."), new Parameter().withParameterKey("CloudFrontAcmCertificate").withParameterValue(Config.get(Config.Key.CLOUDFRONT_ACM_CERTIFICATE_ARN)), new Parameter().withParameterKey("ElbAcmCertificate").withParameterValue(Config.get(Config.Key.ACM_CERTIFICATE_ARN)), new Parameter().withParameterKey("BlogTitle").withParameterValue(blogTitle), new Parameter().withParameterKey("BlogAdminUsername").withParameterValue("admin"), new Parameter().withParameterKey("BlogAdminPassword").withParameterValue(blogPassword), new Parameter().withParameterKey("BlogAdminEMail").withParameterValue("no-reply@widdix.de"), new Parameter().withParameterKey("EFSBackupRetentionPeriod").withParameterValue("0"));
                    final String url = "https://" + subDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
                    final Callable<Boolean> callable = () -> {
                        final HttpResponse response = WS.url(url).timeout(10000).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 200) {
                            throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                        }
                        if (!WS.getResponseAsString(response).contains(blogTitle)) {
                            throw new RuntimeException("http response body contains \"" + blogTitle + "\"");
                        }
                        return true;
                    };
                    Assert.assertTrue("WordPress ready", this.retry(context, callable));
                } finally {
                    this.deleteStackAndRetryOnFailure(context, stackName);
                }
            } finally {
                this.deleteStack(context, vpcStackName);
            }
        } finally {
            this.deleteStack(context, zoneStackName);
        }
    } finally {
        this.deleteKey(context, keyName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 39 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestStaticWebsite method test.

@Test
public void test() {
    final Context context = new Context();
    final String stackNameLambdaEdge = "lambdaedge-index-document-" + this.random8String();
    final String zoneStackName = "zone-" + this.random8String();
    final String stackName = "static-website-" + this.random8String();
    final String subDomainName = stackName;
    final String redirectSubDomainName = "www-" + stackName;
    final String domainName = subDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
    final String redirectDomainName = redirectSubDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
    try {
        this.createStack(context, zoneStackName, "vpc/zone-legacy.yaml", new Parameter().withParameterKey("HostedZoneName").withParameterValue(Config.get(Config.Key.DOMAIN_SUFFIX)), new Parameter().withParameterKey("HostedZoneId").withParameterValue(Config.get(Config.Key.HOSTED_ZONE_ID)));
        try {
            this.createStack(context, stackNameLambdaEdge, "static-website/lambdaedge-index-document.yaml", new Parameter().withParameterKey("DomainName").withParameterValue(domainName), new Parameter().withParameterKey("RedirectDomainName").withParameterValue(redirectDomainName));
            final String viewerRequestLambdaEdgeFunctionVersionARN = this.getStackOutputValue(stackNameLambdaEdge, "ViewerRequestLambdaEdgeFunctionVersionARN");
            try {
                this.createStack(context, stackName, "static-website/static-website.yaml", new Parameter().withParameterKey("ParentZoneStack").withParameterValue(zoneStackName), new Parameter().withParameterKey("SubDomainNameWithDot").withParameterValue(subDomainName + "."), new Parameter().withParameterKey("ViewerRequestLambdaEdgeFunctionVersionARN").withParameterValue(viewerRequestLambdaEdgeFunctionVersionARN), new Parameter().withParameterKey("EnableRedirectSubDomainName").withParameterValue("true"), new Parameter().withParameterKey("RedirectSubDomainNameWithDot").withParameterValue(redirectSubDomainName + "."), new Parameter().withParameterKey("CertificateType").withParameterValue("AcmCertificateArn"), new Parameter().withParameterKey("ExistingCertificate").withParameterValue(Config.get(Config.Key.CLOUDFRONT_ACM_CERTIFICATE_ARN)));
                final String url1 = "https://" + domainName + "/";
                final String url2 = "https://" + domainName + "/folder/";
                final String url3 = "https://" + redirectDomainName + "/";
                try {
                    this.createObject(domainName, "index.html", "hello");
                    this.createObject(domainName, "folder/index.html", "hello");
                    final Callable<HttpResponse> callable1 = () -> {
                        final HttpResponse response = WS.url(url1).timeout(10000).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 200) {
                            throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                        }
                        return response;
                    };
                    final Callable<HttpResponse> callable2 = () -> {
                        final HttpResponse response = WS.url(url2).timeout(10000).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 200) {
                            throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                        }
                        return response;
                    };
                    final Callable<HttpResponse> callable3 = () -> {
                        final HttpResponse response = WS.url(url3).timeout(10000).followRedirect(false).get();
                        // check HTTP response code
                        if (WS.getStatus(response) != 301) {
                            throw new RuntimeException("301 expected, but saw " + WS.getStatus(response));
                        }
                        return response;
                    };
                    this.retry(context, callable1);
                    this.retry(context, callable2);
                    this.retry(context, callable3);
                } finally {
                    this.deleteObject(context, domainName, "folder/index.html");
                    this.deleteObject(context, domainName, "index.html");
                }
            } finally {
                this.deleteStackAndRetryOnFailure(context, stackName);
            }
        } finally {
        // this stack is not deleted because Lambda@Edge functions take up to 3 hours before they can be deleted
        // the cleanup Lambda takes care of those stacks
        // this.deleteStackAndRetryOnFailure(stackNameLambdaEdge);
        }
    } finally {
        this.deleteStack(context, zoneStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Example 40 with Context

use of de.widdix.awscftemplates.Context in project aws-cf-templates by widdix.

the class TestStaticWebsite method testCreateAcmCertificate.

@Test
public void testCreateAcmCertificate() {
    final Context context = new Context();
    final String zoneStackName = "zone-" + this.random8String();
    final String stackName = "static-website-" + this.random8String();
    final String subDomainName = stackName;
    final String redirectSubDomainName = "www-" + stackName;
    final String domainName = subDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
    final String redirectDomainName = redirectSubDomainName + "." + Config.get(Config.Key.DOMAIN_SUFFIX);
    try {
        this.createStack(context, zoneStackName, "vpc/zone-legacy.yaml", new Parameter().withParameterKey("HostedZoneName").withParameterValue(Config.get(Config.Key.DOMAIN_SUFFIX)), new Parameter().withParameterKey("HostedZoneId").withParameterValue(Config.get(Config.Key.HOSTED_ZONE_ID)));
        try {
            this.createStack(context, stackName, "static-website/static-website.yaml", new Parameter().withParameterKey("ParentZoneStack").withParameterValue(zoneStackName), new Parameter().withParameterKey("SubDomainNameWithDot").withParameterValue(subDomainName + "."), new Parameter().withParameterKey("EnableRedirectSubDomainName").withParameterValue("true"), new Parameter().withParameterKey("RedirectSubDomainNameWithDot").withParameterValue(redirectSubDomainName + "."), new Parameter().withParameterKey("CertificateType").withParameterValue("CreateAcmCertificate"));
            final String url1 = "https://" + domainName + "/";
            final String url2 = "https://" + redirectDomainName + "/";
            try {
                this.createObject(domainName, "index.html", "hello");
                final Callable<HttpResponse> callable1 = () -> {
                    final HttpResponse response = WS.url(url1).timeout(10000).get();
                    // check HTTP response code
                    if (WS.getStatus(response) != 200) {
                        throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                    }
                    return response;
                };
                final Callable<HttpResponse> callable2 = () -> {
                    final HttpResponse response = WS.url(url2).timeout(10000).followRedirect(false).get();
                    // check HTTP response code
                    if (WS.getStatus(response) != 200) {
                        throw new RuntimeException("200 expected, but saw " + WS.getStatus(response));
                    }
                    return response;
                };
                this.retry(context, callable1);
                this.retry(context, callable2);
            } finally {
                this.deleteObject(context, domainName, "index.html");
            }
        } finally {
            this.deleteStackAndRetryOnFailure(context, stackName);
        }
    } finally {
        this.deleteStack(context, zoneStackName);
    }
}
Also used : Context(de.widdix.awscftemplates.Context) Parameter(com.amazonaws.services.cloudformation.model.Parameter) HttpResponse(org.apache.http.HttpResponse) ACloudFormationTest(de.widdix.awscftemplates.ACloudFormationTest) Test(org.junit.Test)

Aggregations

Context (de.widdix.awscftemplates.Context)70 Test (org.junit.Test)70 Parameter (com.amazonaws.services.cloudformation.model.Parameter)66 ACloudFormationTest (de.widdix.awscftemplates.ACloudFormationTest)62 HttpResponse (org.apache.http.HttpResponse)19 KeyPair (com.amazonaws.services.ec2.model.KeyPair)4 DescribeContainerInstancesRequest (com.amazonaws.services.ecs.model.DescribeContainerInstancesRequest)2 DescribeContainerInstancesResult (com.amazonaws.services.ecs.model.DescribeContainerInstancesResult)2 ListContainerInstancesRequest (com.amazonaws.services.ecs.model.ListContainerInstancesRequest)2 ListContainerInstancesResult (com.amazonaws.services.ecs.model.ListContainerInstancesResult)2 Session (com.jcraft.jsch.Session)1 Ignore (org.junit.Ignore)1