use of com.amazonaws.services.cloudformation.model.Parameter 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);
}
}
use of com.amazonaws.services.cloudformation.model.Parameter 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);
}
}
use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.
the class TestStaticWebsite method testWAF.
@Test
public void testWAF() {
final Context context = new Context();
final String zoneStackName = "zone-" + this.random8String();
final String wafStackName = "waf-" + 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, wafStackName, "security/waf.yaml", new Parameter().withParameterKey("Scope").withParameterValue("CLOUDFRONT"));
try {
this.createStack(context, stackName, "static-website/static-website.yaml", new Parameter().withParameterKey("ParentZoneStack").withParameterValue(zoneStackName), new Parameter().withParameterKey("ParentWAFStack").withParameterValue(wafStackName), 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.deleteStackAndRetryOnFailure(context, wafStackName);
}
} finally {
this.deleteStack(context, zoneStackName);
}
}
use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.
the class TestVPC2AZsLegacy method test.
@Test
public void test() {
final Context context = new Context();
final String vpcStackName = "vpc-2azs-" + this.random8String();
final String stackName = "vpc-2azs-legacy-" + this.random8String();
try {
this.createStack(context, vpcStackName, "vpc/vpc-2azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue("10"));
final Map<String, String> vpcOutputs = this.getStackOutputs(vpcStackName);
try {
this.createStack(context, stackName, "vpc/vpc-2azs-legacy.yaml", new Parameter().withParameterKey("AZA").withParameterValue(vpcOutputs.get("AZA")), new Parameter().withParameterKey("AZB").withParameterValue(vpcOutputs.get("AZB")), new Parameter().withParameterKey("CidrBlock").withParameterValue(vpcOutputs.get("CidrBlock")), new Parameter().withParameterKey("CidrBlockIPv6").withParameterValue(vpcOutputs.get("CidrBlockIPv6")), new Parameter().withParameterKey("VPC").withParameterValue(vpcOutputs.get("VPC")), new Parameter().withParameterKey("InternetGateway").withParameterValue(vpcOutputs.get("InternetGateway")), new Parameter().withParameterKey("SubnetAPublic").withParameterValue(vpcOutputs.get("SubnetAPublic")), new Parameter().withParameterKey("RouteTableAPublic").withParameterValue(vpcOutputs.get("RouteTableAPublic")), new Parameter().withParameterKey("SubnetBPublic").withParameterValue(vpcOutputs.get("SubnetBPublic")), new Parameter().withParameterKey("RouteTableBPublic").withParameterValue(vpcOutputs.get("RouteTableBPublic")), new Parameter().withParameterKey("SubnetAPrivate").withParameterValue(vpcOutputs.get("SubnetAPrivate")), new Parameter().withParameterKey("RouteTableAPrivate").withParameterValue(vpcOutputs.get("RouteTableAPrivate")), new Parameter().withParameterKey("SubnetBPrivate").withParameterValue(vpcOutputs.get("SubnetBPrivate")), new Parameter().withParameterKey("RouteTableBPrivate").withParameterValue(vpcOutputs.get("RouteTableBPrivate")));
this.testVPCSubnetInternetAccess(context, stackName, "SubnetAPublic");
this.testVPCSubnetInternetAccess(context, stackName, "SubnetBPublic");
} finally {
this.deleteStack(context, stackName);
}
} finally {
this.deleteStack(context, vpcStackName);
}
}
use of com.amazonaws.services.cloudformation.model.Parameter in project aws-cf-templates by widdix.
the class TestVPC3AZsLegacy method test.
@Test
public void test() {
final Context context = new Context();
final String vpcStackName = "vpc-3azs-" + this.random8String();
final String stackName = "vpc-3azs-legacy-" + this.random8String();
try {
this.createStack(context, vpcStackName, "vpc/vpc-3azs.yaml", new Parameter().withParameterKey("ClassB").withParameterValue("10"));
final Map<String, String> vpcOutputs = this.getStackOutputs(vpcStackName);
try {
this.createStack(context, stackName, "vpc/vpc-3azs-legacy.yaml", new Parameter().withParameterKey("AZA").withParameterValue(vpcOutputs.get("AZA")), new Parameter().withParameterKey("AZB").withParameterValue(vpcOutputs.get("AZB")), new Parameter().withParameterKey("AZC").withParameterValue(vpcOutputs.get("AZC")), new Parameter().withParameterKey("CidrBlock").withParameterValue(vpcOutputs.get("CidrBlock")), new Parameter().withParameterKey("CidrBlockIPv6").withParameterValue(vpcOutputs.get("CidrBlockIPv6")), new Parameter().withParameterKey("VPC").withParameterValue(vpcOutputs.get("VPC")), new Parameter().withParameterKey("InternetGateway").withParameterValue(vpcOutputs.get("InternetGateway")), new Parameter().withParameterKey("SubnetAPublic").withParameterValue(vpcOutputs.get("SubnetAPublic")), new Parameter().withParameterKey("RouteTableAPublic").withParameterValue(vpcOutputs.get("RouteTableAPublic")), new Parameter().withParameterKey("SubnetBPublic").withParameterValue(vpcOutputs.get("SubnetBPublic")), new Parameter().withParameterKey("RouteTableBPublic").withParameterValue(vpcOutputs.get("RouteTableBPublic")), new Parameter().withParameterKey("SubnetCPublic").withParameterValue(vpcOutputs.get("SubnetCPublic")), new Parameter().withParameterKey("RouteTableCPublic").withParameterValue(vpcOutputs.get("RouteTableCPublic")), new Parameter().withParameterKey("SubnetAPrivate").withParameterValue(vpcOutputs.get("SubnetAPrivate")), new Parameter().withParameterKey("RouteTableAPrivate").withParameterValue(vpcOutputs.get("RouteTableAPrivate")), new Parameter().withParameterKey("SubnetBPrivate").withParameterValue(vpcOutputs.get("SubnetBPrivate")), new Parameter().withParameterKey("RouteTableBPrivate").withParameterValue(vpcOutputs.get("RouteTableBPrivate")), new Parameter().withParameterKey("SubnetCPrivate").withParameterValue(vpcOutputs.get("SubnetCPrivate")), new Parameter().withParameterKey("RouteTableCPrivate").withParameterValue(vpcOutputs.get("RouteTableCPrivate")));
this.testVPCSubnetInternetAccess(context, stackName, "SubnetAPublic");
this.testVPCSubnetInternetAccess(context, stackName, "SubnetBPublic");
this.testVPCSubnetInternetAccess(context, stackName, "SubnetCPublic");
} finally {
this.deleteStack(context, stackName);
}
} finally {
this.deleteStack(context, vpcStackName);
}
}
Aggregations